Commit eb4bb013 authored by 余玠's avatar 余玠

Merge branch 'v1.12.13-hotfixes'

parents 43df447c aef7e019
...@@ -16,12 +16,10 @@ import io.flutter.embedding.engine.dart.DartExecutor; ...@@ -16,12 +16,10 @@ import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.PluginRegistry;
import io.flutter.view.FlutterMain; import io.flutter.view.FlutterMain;
import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class FlutterBoost { public class FlutterBoost {
private Platform mPlatform; private Platform mPlatform;
private FlutterViewContainerManager mManager; private FlutterViewContainerManager mManager;
...@@ -70,7 +68,6 @@ public class FlutterBoost { ...@@ -70,7 +68,6 @@ public class FlutterBoost {
if (mPlatform.whenEngineStart() == ConfigBuilder.ANY_ACTIVITY_CREATED) { if (mPlatform.whenEngineStart() == ConfigBuilder.ANY_ACTIVITY_CREATED) {
doInitialFlutter(); doInitialFlutter();
} }
} }
@Override @Override
...@@ -81,7 +78,7 @@ public class FlutterBoost { ...@@ -81,7 +78,7 @@ public class FlutterBoost {
if (mCurrentActiveActivity == null) { if (mCurrentActiveActivity == null) {
Debuger.log("Application entry foreground"); Debuger.log("Application entry foreground");
if (createEngine() != null) { if (mEngine != null) {
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
map.put("type", "foreground"); map.put("type", "foreground");
channel().sendEvent("lifecycle", map); channel().sendEvent("lifecycle", map);
...@@ -113,7 +110,7 @@ public class FlutterBoost { ...@@ -113,7 +110,7 @@ public class FlutterBoost {
if (mCurrentActiveActivity == activity) { if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background"); Debuger.log("Application entry background");
if (createEngine() != null) { if (mEngine != null) {
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
map.put("type", "background"); map.put("type", "background");
channel().sendEvent("lifecycle", map); channel().sendEvent("lifecycle", map);
...@@ -137,7 +134,7 @@ public class FlutterBoost { ...@@ -137,7 +134,7 @@ public class FlutterBoost {
if (mCurrentActiveActivity == activity) { if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background"); Debuger.log("Application entry background");
if (createEngine() != null) { if (mEngine != null) {
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
map.put("type", "background"); map.put("type", "background");
channel().sendEvent("lifecycle", map); channel().sendEvent("lifecycle", map);
...@@ -158,9 +155,9 @@ public class FlutterBoost { ...@@ -158,9 +155,9 @@ public class FlutterBoost {
} }
public void doInitialFlutter() { public void doInitialFlutter() {
if (mEngine != null) {
return;
if (mEngine != null) return; }
if (mPlatform.lifecycleListener != null) { if (mPlatform.lifecycleListener != null) {
mPlatform.lifecycleListener.beforeCreateEngine(); mPlatform.lifecycleListener.beforeCreateEngine();
...@@ -182,7 +179,6 @@ public class FlutterBoost { ...@@ -182,7 +179,6 @@ public class FlutterBoost {
); );
flutterEngine.getDartExecutor().executeDartEntrypoint(entrypoint); flutterEngine.getDartExecutor().executeDartEntrypoint(entrypoint);
} }
...@@ -318,7 +314,6 @@ public class FlutterBoost { ...@@ -318,7 +314,6 @@ public class FlutterBoost {
private FlutterEngine createEngine() { private FlutterEngine createEngine() {
if (mEngine == null) { if (mEngine == null) {
FlutterMain.startInitialization(mPlatform.getApplication()); FlutterMain.startInitialization(mPlatform.getApplication());
FlutterShellArgs flutterShellArgs = new FlutterShellArgs(new String[0]); FlutterShellArgs flutterShellArgs = new FlutterShellArgs(new String[0]);
......
...@@ -51,6 +51,13 @@ ...@@ -51,6 +51,13 @@
// [self.flutterContainer.view setNeedsLayout]; // [self.flutterContainer.view setNeedsLayout];
// [self.flutterContainer.view layoutIfNeeded]; // [self.flutterContainer.view layoutIfNeeded];
} }
//NOTES: embed情景下必须实现!!!
- (void)didMoveToParentViewController:(UIViewController *)parent {
[self.flutterContainer didMoveToParentViewController:parent];
[super didMoveToParentViewController:parent];
}
/* /*
#pragma mark - Navigation #pragma mark - Navigation
...@@ -61,4 +68,8 @@ ...@@ -61,4 +68,8 @@
} }
*/ */
- (void)dealloc{
NSLog(@"dealloc native controller%p", self.flutterContainer);
}
@end @end
...@@ -19,7 +19,9 @@ class _MyAppState extends State<MyApp> { ...@@ -19,7 +19,9 @@ class _MyAppState extends State<MyApp> {
FlutterBoost.singleton.registerPageBuilders({ FlutterBoost.singleton.registerPageBuilders({
'embeded': (pageName, params, _)=>EmbededFirstRouteWidget(), 'embeded': (pageName, params, _)=>EmbededFirstRouteWidget(),
'first': (pageName, params, _) => FirstRouteWidget(), 'first': (pageName, params, _) => FirstRouteWidget(),
'firstFirst': (pageName, params, _) => FirstFirstRouteWidget(),
'second': (pageName, params, _) => SecondRouteWidget(), 'second': (pageName, params, _) => SecondRouteWidget(),
'secondStateful': (pageName, params, _) => SecondStatefulRouteWidget(),
'tab': (pageName, params, _) => TabRouteWidget(), 'tab': (pageName, params, _) => TabRouteWidget(),
'platformView': (pageName, params, _) => PlatformRouteWidget(), 'platformView': (pageName, params, _) => PlatformRouteWidget(),
'flutterFragment': (pageName, params, _) => FragmentRouteWidget(params), 'flutterFragment': (pageName, params, _) => FragmentRouteWidget(params),
......
...@@ -3,7 +3,45 @@ import 'package:flutter/material.dart'; ...@@ -3,7 +3,45 @@ import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart'; import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_boost_example/platform_view.dart'; import 'package:flutter_boost_example/platform_view.dart';
class FirstRouteWidget extends StatelessWidget { class FirstRouteWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new _FirstRouteWidgetState();
}
}
class _FirstRouteWidgetState extends State<FirstRouteWidget>{
_FirstRouteWidgetState();
@override
void initState() {
print('initState');
super.initState();
}
@override
void didChangeDependencies() {
print('didChangeDependencies');
super.didChangeDependencies();
}
@override
void didUpdateWidget(FirstRouteWidget oldWidget) {
print('didUpdateWidget');
super.didUpdateWidget(oldWidget);
}
@override
void deactivate() {
print('deactivate');
super.deactivate();
}
@override
void dispose() {
print('[XDEBUG] - FirstRouteWidget is disposing~');
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
...@@ -22,13 +60,22 @@ class FirstRouteWidget extends StatelessWidget { ...@@ -22,13 +60,22 @@ class FirstRouteWidget extends StatelessWidget {
print("open natve page!"); print("open natve page!");
FlutterBoost.singleton.open("native").then((Map value) { FlutterBoost.singleton.open("native").then((Map value) {
print( print(
"call me when page is finished. did recieve second route result $value"); "call me when page is finished. did recieve native route result $value");
}); });
}, },
), ),
RaisedButton(
RaisedButton( child: Text('Open FF route'),
child: Text('Open second route'), onPressed: () {
print("open FF page!");
FlutterBoost.singleton.open("firstFirst").then((Map value) {
print(
"call me when page is finished. did recieve FF route result $value");
});
},
),
RaisedButton(
child: Text('Open second route1'),
onPressed: () { onPressed: () {
print("open second page!"); print("open second page!");
FlutterBoost.singleton.open("second").then((Map value) { FlutterBoost.singleton.open("second").then((Map value) {
...@@ -39,6 +86,16 @@ class FirstRouteWidget extends StatelessWidget { ...@@ -39,6 +86,16 @@ class FirstRouteWidget extends StatelessWidget {
), ),
RaisedButton( RaisedButton(
child: Text('Present second stateful route'),
onPressed: () {
print("Present second stateful page!");
FlutterBoost.singleton.open("secondStateful",urlParams:<dynamic,dynamic>{"present":true}).then((Map value) {
print(
"call me when page is finished. did recieve second stateful route result $value");
});
},
),
RaisedButton(
child: Text('Present second route'), child: Text('Present second route'),
onPressed: () { onPressed: () {
print("Present second page!"); print("Present second page!");
...@@ -54,14 +111,87 @@ class FirstRouteWidget extends StatelessWidget { ...@@ -54,14 +111,87 @@ class FirstRouteWidget extends StatelessWidget {
); );
} }
} }
class FirstFirstRouteWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new _FirstFirstRouteWidgetState();
}
}
class _FirstFirstRouteWidgetState extends State<FirstFirstRouteWidget>{
_FirstFirstRouteWidgetState();
@override
void initState() {
print('initState');
super.initState();
}
@override
void didChangeDependencies() {
print('didChangeDependencies');
super.didChangeDependencies();
}
@override
void didUpdateWidget(FirstFirstRouteWidget oldWidget) {
print('didUpdateWidget');
super.didUpdateWidget(oldWidget);
}
@override
void deactivate() {
print('deactivate');
super.deactivate();
}
@override
void dispose() {
print('[XDEBUG] - FirstFirstRouteWidget is disposing~');
super.dispose();
}
class EmbededFirstRouteWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(
title: Text('First Route'),
),
body: Center( body: Center(
child: RaisedButton( child: RaisedButton(
child: Text('Open second route'), child: Text('Open first route'),
onPressed: () {
print("open first page again!");
FlutterBoost.singleton.open("first").then((Map value){
print("did recieve first route result");
print("did recieve first route result $value");
});
},
),
),
);
}
}
class EmbededFirstRouteWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _EmbededFirstRouteWidgetState();
}
}
class _EmbededFirstRouteWidgetState extends State<EmbededFirstRouteWidget> {
@override
Widget build(BuildContext context) {
print('_EmbededFirstRouteWidgetState build called!');
return Scaffold(
body: Center(
child: RaisedButton(
child: Text('Open second route2'),
onPressed: () { onPressed: () {
print("open second page!"); print("open second page!");
FlutterBoost.singleton.open("second").then((Map value) { FlutterBoost.singleton.open("second").then((Map value) {
...@@ -73,6 +203,48 @@ class EmbededFirstRouteWidget extends StatelessWidget { ...@@ -73,6 +203,48 @@ class EmbededFirstRouteWidget extends StatelessWidget {
), ),
); );
} }
@override
void dispose() {
print('[XDEBUG]:_EmbededFirstRouteWidgetState disposing~');
super.dispose();
}
}
class SecondStatefulRouteWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _SecondStatefulRouteWidgetState();
}
}
class _SecondStatefulRouteWidgetState extends State<SecondStatefulRouteWidget>{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("SecondStateful Route"),
),
body: Center(
child: RaisedButton(
onPressed: () {
// Navigate back to first route when tapped.
BoostContainerSettings settings =
BoostContainer.of(context).settings;
FlutterBoost.singleton.close(settings.uniqueId,
result: <dynamic,dynamic>{"result": "data from second"});
},
child: Text('Go back with result!'),
),
),
);
}
@override
void dispose() {
print('[XDEBUG]:SecondStatefulRouteWidget disposing~');
super.dispose();
}
} }
class SecondRouteWidget extends StatelessWidget { class SecondRouteWidget extends StatelessWidget {
...@@ -111,7 +283,7 @@ class TabRouteWidget extends StatelessWidget { ...@@ -111,7 +283,7 @@ class TabRouteWidget extends StatelessWidget {
onPressed: () { onPressed: () {
FlutterBoost.singleton.open("second"); FlutterBoost.singleton.open("second");
}, },
child: Text('Open second route'), child: Text('Open second route3'),
), ),
), ),
); );
...@@ -432,6 +604,7 @@ class _PushWidgetState extends State<PushWidget> { ...@@ -432,6 +604,7 @@ class _PushWidgetState extends State<PushWidget> {
@override @override
void dispose() { void dispose() {
// TODO: implement dispose // TODO: implement dispose
print('[XDEBUG] - PushWidget is disposing~');
super.dispose(); super.dispose();
_backPressedListenerUnsub?.call(); _backPressedListenerUnsub?.call();
} }
......
...@@ -66,6 +66,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -66,6 +66,7 @@ NS_ASSUME_NONNULL_BEGIN
onPageFinished:(void (^)(NSDictionary *))resultCallback onPageFinished:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion; completion:(void (^)(BOOL))completion;
- (void)attachToPreviousContainer;
- (void)didInitPageContainer:(NSString *)url - (void)didInitPageContainer:(NSString *)url
params:(NSDictionary *)urlParams params:(NSDictionary *)urlParams
......
...@@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol FLBFlutterProvider <NSObject> @protocol FLBFlutterProvider <NSObject>
@required @required
- (FlutterEngine *)engine; - (FlutterEngine *)engine;
- (void)atacheToViewController:(FlutterViewController *)vc; - (BOOL)atacheToViewController:(FlutterViewController *)vc;
- (void)detach; - (void)detach;
- (void)prepareEngineIfNeeded; - (void)prepareEngineIfNeeded;
- (void)pause; - (void)pause;
......
...@@ -26,10 +26,12 @@ ...@@ -26,10 +26,12 @@
#import "FlutterBoost.h" #import "FlutterBoost.h"
#import "FLBFlutterContainerManager.h" #import "FLBFlutterContainerManager.h"
#import "FLBFlutterEngine.h" #import "FLBFlutterEngine.h"
#import "FLBFlutterViewContainer.h"
@interface FLBFlutterApplication() @interface FLBFlutterApplication()
@property (nonatomic,strong) FLBFlutterContainerManager *manager; @property (nonatomic,strong) FLBFlutterContainerManager *manager;
@property (nonatomic,strong) id<FLBFlutterProvider> viewProvider; @property (nonatomic,strong) id<FLBFlutterProvider> viewProvider;
@property (nonatomic, weak, readonly)FlutterViewController * previousViewController;
@property (nonatomic,assign) BOOL isRunning; @property (nonatomic,assign) BOOL isRunning;
@property (nonatomic,strong) NSMutableDictionary *pageResultCallbacks; @property (nonatomic,strong) NSMutableDictionary *pageResultCallbacks;
@property (nonatomic,strong) NSMutableDictionary *callbackCache; @property (nonatomic,strong) NSMutableDictionary *callbackCache;
...@@ -156,6 +158,13 @@ ...@@ -156,6 +158,13 @@
return self.flutterProvider.engine.viewController; return self.flutterProvider.engine.viewController;
} }
- (void)attachToPreviousContainer{
if([self.viewProvider atacheToViewController:self.previousViewController]){
[self.previousViewController.view setNeedsLayout];
[(FLBFlutterViewContainer*)self.previousViewController surfaceUpdated:YES];
}
}
- (void)close:(NSString *)uniqueId - (void)close:(NSString *)uniqueId
result:(NSDictionary *)resultData result:(NSDictionary *)resultData
exts:(NSDictionary *)exts exts:(NSDictionary *)exts
...@@ -189,7 +198,7 @@ ...@@ -189,7 +198,7 @@
[newParams setObject:cid?cid:@"__default#0__" forKey:kPageCallBackId]; [newParams setObject:cid?cid:@"__default#0__" forKey:kPageCallBackId];
urlParams = newParams; urlParams = newParams;
} }
_previousViewController = [self flutterViewController];
_callbackCache[cid] = resultCallback; _callbackCache[cid] = resultCallback;
if([urlParams[@"present"]respondsToSelector:@selector(boolValue)] && [urlParams[@"present"] boolValue] && [self.platform respondsToSelector:@selector(present:urlParams:exts:completion:)]){ if([urlParams[@"present"]respondsToSelector:@selector(boolValue)] && [urlParams[@"present"] boolValue] && [self.platform respondsToSelector:@selector(present:urlParams:exts:completion:)]){
[self.platform present:url [self.platform present:url
......
...@@ -97,17 +97,19 @@ ...@@ -97,17 +97,19 @@
arguments:@{@"type":@"foreground"}]; arguments:@{@"type":@"foreground"}];
} }
- (void)atacheToViewController:(FlutterViewController *)vc - (BOOL)atacheToViewController:(FlutterViewController *)vc
{ {
if(_engine.viewController != vc){ if(_engine.viewController != vc){
// [(FLBFlutterViewContainer *)_engine.viewController surfaceUpdated:NO];
_engine.viewController = vc; _engine.viewController = vc;
return YES;
} }
return NO;
} }
- (void)detach - (void)detach
{ {
if(_engine.viewController != _dummy){ if(_engine.viewController != _dummy){
[(FLBFlutterViewContainer *)_engine.viewController surfaceUpdated:NO];
_engine.viewController = _dummy; _engine.viewController = _dummy;
} }
} }
......
...@@ -118,10 +118,6 @@ ...@@ -118,10 +118,6 @@
if(!_name && name){ if(!_name && name){
_name = name; _name = name;
_params = params; _params = params;
[BoostMessageChannel didInitPageContainer:^(NSNumber *r) {}
pageName:name
params:params
uniqueId:[self uniqueIDString]];
} }
} }
...@@ -160,9 +156,38 @@ static NSUInteger kInstanceCounter = 0; ...@@ -160,9 +156,38 @@ static NSUInteger kInstanceCounter = 0;
[self.class instanceCounterIncrease]; [self.class instanceCounterIncrease];
} }
- (void)willMoveToParentViewController:(UIViewController *)parent {
if (parent && _name) {
//当VC将要被移动到Parent中的时候,才出发flutter层面的page init
[BoostMessageChannel didInitPageContainer:^(NSNumber *r) {}
pageName:_name
params:_params
uniqueId:[self uniqueIDString]];
}
[super willMoveToParentViewController:parent];
}
- (void)didMoveToParentViewController:(UIViewController *)parent {
if (!parent) {
//当VC被移出parent时,就通知flutter层销毁page
[self notifyWillDealloc];
}
[super didMoveToParentViewController:parent];
}
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
[super dismissViewControllerAnimated:flag completion:^(){
if (completion) {
completion();
}
//当VC被dismiss时,就通知flutter层销毁page
[self notifyWillDealloc];
}];
}
- (void)dealloc - (void)dealloc
{ {
[self notifyWillDealloc];
[NSNotificationCenter.defaultCenter removeObserver:self]; [NSNotificationCenter.defaultCenter removeObserver:self];
} }
...@@ -262,11 +287,6 @@ static NSUInteger kInstanceCounter = 0; ...@@ -262,11 +287,6 @@ static NSUInteger kInstanceCounter = 0;
pageName:_name pageName:_name
params:_params params:_params
uniqueId:self.uniqueIDString]; uniqueId:self.uniqueIDString];
//如果当前不可见vc和engine所持有的vc一致。在FlutterVC在混合栈中是最后一张页面,如tab中的页面
// if (self == FLUTTER_VC)
// {
// [self surfaceUpdated:NO];
// }
[super bridge_viewDidDisappear:animated]; [super bridge_viewDidDisappear:animated];
} }
......
...@@ -102,7 +102,7 @@ class ContainerCoordinator { ...@@ -102,7 +102,7 @@ class ContainerCoordinator {
Map map = event; Map map = event;
final String type = map['type']; final String type = map['type'];
Logger.log("onEvent $type"); Logger.log('onEvent $type');
switch (type) { switch (type) {
//Handler back key pressed event. //Handler back key pressed event.
...@@ -242,7 +242,7 @@ class ContainerCoordinator { ...@@ -242,7 +242,7 @@ class ContainerCoordinator {
ContainerLifeCycle.Appear); ContainerLifeCycle.Appear);
Logger.log( Logger.log(
'native containner did show,\nmanager dump:\n${FlutterBoost.containerManager?.dump()}'); 'native containner did show-$name,\nmanager dump:\n${FlutterBoost.containerManager?.dump()}');
return true; return true;
} }
...@@ -275,7 +275,7 @@ class ContainerCoordinator { ...@@ -275,7 +275,7 @@ class ContainerCoordinator {
FlutterBoost.containerManager?.remove(pageId); FlutterBoost.containerManager?.remove(pageId);
Logger.log( Logger.log(
'native containner dealloc, \n manager dump:\n${FlutterBoost.containerManager?.dump()}'); 'native containner dealloc for $name, \n manager dump:\n${FlutterBoost.containerManager?.dump()}');
return true; return true;
} }
......
...@@ -183,9 +183,11 @@ class ContainerManagerState extends State<BoostContainerManager> { ...@@ -183,9 +183,11 @@ class ContainerManagerState extends State<BoostContainerManager> {
if (SchedulerBinding.instance.schedulerPhase == if (SchedulerBinding.instance.schedulerPhase ==
SchedulerPhase.persistentCallbacks) { SchedulerPhase.persistentCallbacks) {
SchedulerBinding.instance.addPostFrameCallback((Duration duration) { SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
Logger.log('_refreshOverlayEntries in addPostFrameCallback');
_refreshOverlayEntries(); _refreshOverlayEntries();
}); });
} else { } else {
Logger.log('_refreshOverlayEntries in setState');
_refreshOverlayEntries(); _refreshOverlayEntries();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment