Skip to content

Commit

Permalink
page create and destroy event adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdPaleLight committed May 6, 2021
1 parent f53f0be commit 62c8880
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 142 deletions.
8 changes: 4 additions & 4 deletions example/lib/flutter_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget>
}

@override
void onPageShow({bool isForegroundEvent}) {
void onPageShow() {
Logger.log(
'$_kTag#onPageShow, ${widget.uniqueId}, isForegroundEvent=$isForegroundEvent, $this');
'$_kTag#onPageShow, ${widget.uniqueId}, $this');
}

void onPageHide({bool isBackgroundEvent}) {
void onPageHide() {
Logger.log(
'$_kTag#onPageHide, ${widget.uniqueId}, isBackgroundEvent=$isBackgroundEvent, $this');
'$_kTag#onPageHide, ${widget.uniqueId}, $this');
}

@override
Expand Down
16 changes: 8 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ import 'package:flutter_boost/logger.dart';


void main() {
PageVisibilityBinding.instance.addGlobalObserver(AppGlobalPageVisiblityObserver());
PageVisibilityBinding.instance.addGlobalObserver(AppGlobalPageVisibilityObserver());
runApp(MyApp());
}

class AppGlobalPageVisiblityObserver extends GlobalPageVisiblityObserver {
class AppGlobalPageVisibilityObserver extends GlobalPageVisibilityObserver {
void onPageCreate(Route<dynamic> route) {
Logger.log('boost_lifecycle: AppGlobalPageVisiblityObserver.onPageCreate route:${route.settings.name}');
Logger.log('boost_lifecycle: AppGlobalPageVisibilityObserver.onPageCreate route:${route.settings.name}');
}

void onPageShow(Route<dynamic> route, {bool isForegroundEvent = false}) {
Logger.log('boost_lifecycle: AppGlobalPageVisiblityObserver.onPageShow route:${route.settings.name} isForegroundEvent:$isForegroundEvent');
void onPageShow(Route<dynamic> route) {
Logger.log('boost_lifecycle: AppGlobalPageVisibilityObserver.onPageShow route:${route.settings.name}');
}

void onPageHide(Route<dynamic> route, {bool isBackgroundEvent = false}) {
Logger.log('boost_lifecycle: AppGlobalPageVisiblityObserver.onPageHide route:${route.settings.name} isBackgroundEvent:$isBackgroundEvent');
void onPageHide(Route<dynamic> route) {
Logger.log('boost_lifecycle: AppGlobalPageVisibilityObserver.onPageHide route:${route.settings.name}');
}

void onPageDestroy(Route<dynamic> route) {
Logger.log('boost_lifecycle: AppGlobalPageVisiblityObserver.onPageDestroy route:${route.settings.name}');
Logger.log('boost_lifecycle: AppGlobalPageVisibilityObserver.onPageDestroy route:${route.settings.name}');
}
}

Expand Down
9 changes: 5 additions & 4 deletions example/lib/tab/simple_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ class _SimpleWidgetState extends State<SimpleWidget>
}

@override
void onPageShow({bool isForegroundEvent}) {
print('$_kTag#onPageShow, ${widget.uniqueId}, isForegroundEvent=$isForegroundEvent, $this');
void onPageShow() {
print('$_kTag#onPageShow, ${widget.uniqueId}, $this');
}

void onPageHide({bool isBackgroundEvent}) {
print('$_kTag#onPageHide, ${widget.uniqueId}, isBackgroundEvent=$isBackgroundEvent, $this');
@override
void onPageHide() {
print('$_kTag#onPageHide, ${widget.uniqueId}, $this');
}

@override
Expand Down
59 changes: 20 additions & 39 deletions lib/boost_lifecycle_binding.dart
Original file line number Diff line number Diff line change
@@ -1,46 +1,23 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_boost/boost_container.dart';
import 'package:flutter_boost/page_visibility.dart';

import 'logger.dart';

class BoostLifecycleBinding {
BoostLifecycleBinding._();

static final BoostLifecycleBinding instance = BoostLifecycleBinding._();

void containerDidMoveToTop(
BoostContainer container, BoostContainer previousContainer) {
// Logger.log('boost_lifecycle: BoostLifecycleBinding.containerDidMoveToTop');
// PageVisibilityBinding.instance
// .dispatchPageShowEvent(container.topPage.route);
// if (previousContainer.topPage.route != null) {
// PageVisibilityBinding.instance
// .dispatchPageHideEvent(previousContainer.topPage.route);
// }
}

void containerDidPush(
BoostContainer container, BoostContainer previousContainer) {
// Logger.log('boost_lifecycle: BoostLifecycleBinding.containerDidPush');
// PageVisibilityBinding.instance
// .dispatchPageShowEvent(container.topPage.route);
// if (previousContainer.topPage.route != null) {
// PageVisibilityBinding.instance
// .dispatchPageHideEvent(previousContainer.topPage.route);
// }
Logger.log('boost_lifecycle: BoostLifecycleBinding.containerDidPush');
PageVisibilityBinding.instance.dispatchPageCreateEvent(container.topPage.route);
}

void containerDidPop(
BoostContainer container, BoostContainer previousContainer) {
// Logger.log('boost_lifecycle: BoostLifecycleBinding.containerDidPop');
}

void containerDidHide(BoostContainer container) {
Logger.log('boost_lifecycle: BoostLifecycleBinding.containerDidHide');
PageVisibilityBinding.instance
.dispatchPageHideEvent(container.topPage.route);

Logger.log('boost_lifecycle: BoostLifecycleBinding.containerDidPop');
PageVisibilityBinding.instance.dispatchPageDestroyEvent(container.topPage.route);
}

void containerDidShow(BoostContainer container) {
Expand All @@ -49,22 +26,15 @@ class BoostLifecycleBinding {
.dispatchPageShowEvent(container.topPage.route);
}

void appDidEnterForeground(BoostContainer container) {
Logger.log('boost_lifecycle: BoostLifecycleBinding.appDidEnterForeground');
PageVisibilityBinding.instance.dispatchPageShowEvent(
container.topPage.route,
isForegroundEvent: true);
}

void appDidEnterBackground(BoostContainer container) {
Logger.log('boost_lifecycle: BoostLifecycleBinding.appDidEnterBackground');
PageVisibilityBinding.instance.dispatchPageHideEvent(
container.topPage.route,
isBackgroundEvent: true);
void containerDidHide(BoostContainer container) {
Logger.log('boost_lifecycle: BoostLifecycleBinding.containerDidHide');
PageVisibilityBinding.instance
.dispatchPageHideEvent(container.topPage.route);
}

void routeDidPush(Route<dynamic> route, Route<dynamic> previousRoute) {
Logger.log('boost_lifecycle: BoostLifecycleBinding.routeDidPush');
PageVisibilityBinding.instance.dispatchPageCreateEvent(route);
PageVisibilityBinding.instance.dispatchPageShowEvent(route);
PageVisibilityBinding.instance.dispatchPageHideEvent(previousRoute);
}
Expand All @@ -73,5 +43,16 @@ class BoostLifecycleBinding {
Logger.log('boost_lifecycle: BoostLifecycleBinding.routeDidPop');
PageVisibilityBinding.instance.dispatchPageHideEvent(route);
PageVisibilityBinding.instance.dispatchPageShowEvent(previousRoute);
PageVisibilityBinding.instance.dispatchPageDestroyEvent(route);
}


void appDidEnterForeground(BoostContainer container) {
Logger.log('boost_lifecycle: BoostLifecycleBinding.appDidEnterForeground');
}

void appDidEnterBackground(BoostContainer container) {
Logger.log('boost_lifecycle: BoostLifecycleBinding.appDidEnterBackground');
}

}
7 changes: 3 additions & 4 deletions lib/flutter_boost_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ class FlutterBoostAppState extends State<FlutterBoostApp> {
containers.remove(existed);
containers.add(existed);
refresh();
BoostLifecycleBinding.instance.containerDidMoveToTop(container, previousContainer);
}
// else {
// PageVisibilityBinding.instance
Expand Down Expand Up @@ -353,8 +352,8 @@ class FlutterBoostAppState extends State<FlutterBoostApp> {
if (container != null) {
// Gets the first internal route of the current container
_route = container.pages.first.route;
containers.removeWhere(
(BoostContainer entry) => entry.pageInfo?.uniqueId == uniqueId);
containers.remove(container);
BoostLifecycleBinding.instance.containerDidPop(container, topContainer);
} else {
for (BoostContainer container in containers) {
final BoostPage<dynamic> _target = container.pages.firstWhere(
Expand All @@ -366,7 +365,7 @@ class FlutterBoostAppState extends State<FlutterBoostApp> {
}
}
refresh();
PageVisibilityBinding.instance.dispatchPageDestroyEvent(_route);
// PageVisibilityBinding.instance.dispatchPageDestroyEvent(_route);
Logger.log('remove, uniqueId=$uniqueId, $containers');
}

Expand Down
Loading

0 comments on commit 62c8880

Please sign in to comment.