Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix page reload. #1109

Merged
merged 3 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kraken/lib/src/bridge/from_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ final Pointer<NativeFunction<NativeInvokeModule>> _nativeInvokeModule = Pointer.
// Register reloadApp
typedef NativeReloadApp = Void Function(Int32 contextId);

void _reloadApp(int contextId) {
void _reloadApp(int contextId) async {
KrakenController controller = KrakenController.getControllerOfJSContextId(contextId)!;

try {
controller.reload();
await controller.reload();
} catch (e, stack) {
print('Dart Error: $e\n$stack');
}
Expand Down
9 changes: 6 additions & 3 deletions kraken/lib/src/dom/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -701,13 +701,16 @@ class Element extends Node

/// Release any resources held by [renderBoxModel].
@override
void disposeRenderObject() {
void disposeRenderObject({ bool deep = false }) {
if (renderBoxModel == null) return;

willDetachRenderer();

for (Node child in childNodes) {
child.disposeRenderObject();
// Dispose all renderObject when deep.
if (deep) {
for (Node child in childNodes) {
child.disposeRenderObject(deep: true);
}
}

didDetachRenderer();
Expand Down
2 changes: 1 addition & 1 deletion kraken/lib/src/dom/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ abstract class Node extends EventTarget implements RenderObjectNode, LifecycleCa
void attachTo(Element parent, {RenderBox? after}) {}

/// Release any resources held by referenced render object.
void disposeRenderObject() {}
void disposeRenderObject({ bool deep = false}) {}

/// Release any resources held by this node.
@override
Expand Down
2 changes: 1 addition & 1 deletion kraken/lib/src/dom/sliver_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class RenderSliverElementChildManager implements RenderSliverBoxChildManager {
if (index < renderNodes.length) {
renderNodes
.elementAt(index)
.disposeRenderObject();
.disposeRenderObject(deep: true);
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion kraken/lib/src/dom/text_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class TextNode extends Node {

// Detach renderObject of current node from parent
@override
void disposeRenderObject() {
void disposeRenderObject({ bool deep = false }) {
detach();
_renderTextBox = null;
}
Expand Down
28 changes: 19 additions & 9 deletions kraken/lib/src/launcher/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class KrakenViewController
this.navigationDelegate,
this.gestureListener,
this.widgetDelegate,
// Viewport won't change when kraken page reload, should reuse previous page's viewportBox.
RenderViewportBox? originalViewport
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewport?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不能用 this.viewport,已经有这个变量了

}) {
if (enableDebug) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
Expand All @@ -128,11 +130,18 @@ class KrakenViewController
PerformanceTiming.instance().mark(PERF_CREATE_VIEWPORT_START);
}

viewport = RenderViewportBox(
if (originalViewport != null) {
// Should update to newlast controller.
originalViewport.controller = rootController;
viewport = originalViewport;
} else {
viewport = RenderViewportBox(
background: background,
viewportSize: Size(viewportWidth, viewportHeight),
gestureListener: gestureListener,
controller: rootController);
controller: rootController
);
}

if (kProfileMode) {
PerformanceTiming.instance().mark(PERF_CREATE_VIEWPORT_END);
Expand Down Expand Up @@ -957,13 +966,14 @@ class KrakenController {
allocateNewPage(_view.contextId);

_view = KrakenViewController(view.viewportWidth, view.viewportHeight,
background: _view.background,
enableDebug: _view.enableDebug,
contextId: _view.contextId,
rootController: this,
navigationDelegate: _view.navigationDelegate,
gestureListener: _view.gestureListener,
widgetDelegate: _view.widgetDelegate
background: _view.background,
enableDebug: _view.enableDebug,
contextId: _view.contextId,
rootController: this,
navigationDelegate: _view.navigationDelegate,
gestureListener: _view.gestureListener,
widgetDelegate: _view.widgetDelegate,
originalViewport: _view.viewport
);

_module = KrakenModuleController(this, _view.contextId);
Expand Down