Commit b3a5d505 authored by 余玠's avatar 余玠 Committed by justin

Pick from master

parent ea007356
......@@ -17,7 +17,6 @@ import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.loader.FlutterLoader;
import io.flutter.view.FlutterMain;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
......
......@@ -51,6 +51,13 @@
// [self.flutterContainer.view setNeedsLayout];
// [self.flutterContainer.view layoutIfNeeded];
}
//NOTES: embed情景下必须实现!!!
- (void)didMoveToParentViewController:(UIViewController *)parent {
[self.flutterContainer didMoveToParentViewController:parent];
[super didMoveToParentViewController:parent];
}
/*
#pragma mark - Navigation
......@@ -61,4 +68,8 @@
}
*/
- (void)dealloc{
NSLog(@"dealloc native controller%p", self.flutterContainer);
}
@end
......@@ -19,7 +19,9 @@ class _MyAppState extends State<MyApp> {
FlutterBoost.singleton.registerPageBuilders({
'embeded': (pageName, params, _)=>EmbededFirstRouteWidget(),
'first': (pageName, params, _) => FirstRouteWidget(),
'firstFirst': (pageName, params, _) => FirstFirstRouteWidget(),
'second': (pageName, params, _) => SecondRouteWidget(),
'secondStateful': (pageName, params, _) => SecondStatefulRouteWidget(),
'tab': (pageName, params, _) => TabRouteWidget(),
'platformView': (pageName, params, _) => PlatformRouteWidget(),
'flutterFragment': (pageName, params, _) => FragmentRouteWidget(params),
......
......@@ -3,7 +3,45 @@ import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.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
Widget build(BuildContext context) {
return Scaffold(
......@@ -22,13 +60,22 @@ class FirstRouteWidget extends StatelessWidget {
print("open natve page!");
FlutterBoost.singleton.open("native").then((Map<dynamic,dynamic> value) {
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(
child: Text('Open second route'),
child: Text('Open FF 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: () {
print("open second page!");
FlutterBoost.singleton.open("second").then((Map<dynamic,dynamic> value) {
......@@ -38,6 +85,16 @@ class FirstRouteWidget extends StatelessWidget {
},
),
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'),
onPressed: () {
......@@ -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();
}
class EmbededFirstRouteWidget extends StatelessWidget {
@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();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child: RaisedButton(
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 route'),
child: Text('Open second route2'),
onPressed: () {
print("open second page!");
FlutterBoost.singleton.open("second").then((Map<dynamic,dynamic> value) {
......@@ -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 {
......@@ -111,7 +283,7 @@ class TabRouteWidget extends StatelessWidget {
onPressed: () {
FlutterBoost.singleton.open("second");
},
child: Text('Open second route'),
child: Text('Open second route3'),
),
),
);
......@@ -432,6 +604,7 @@ class _PushWidgetState extends State<PushWidget> {
@override
void dispose() {
// TODO: implement dispose
print('[XDEBUG] - PushWidget is disposing~');
super.dispose();
_backPressedListenerUnsub?.call();
}
......
......@@ -66,6 +66,7 @@ NS_ASSUME_NONNULL_BEGIN
onPageFinished:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion;
- (void)attachToPreviousContainer;
- (void)didInitPageContainer:(NSString *)url
params:(NSDictionary *)urlParams
......
......@@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol FLBFlutterProvider <NSObject>
@required
- (FlutterEngine *)engine;
- (void)atacheToViewController:(FlutterViewController *)vc;
- (BOOL)atacheToViewController:(FlutterViewController *)vc;
- (void)detach;
- (void)prepareEngineIfNeeded;
- (void)pause;
......
......@@ -26,10 +26,12 @@
#import "FlutterBoost.h"
#import "FLBFlutterContainerManager.h"
#import "FLBFlutterEngine.h"
#import "FLBFlutterViewContainer.h"
@interface FLBFlutterApplication()
@property (nonatomic,strong) FLBFlutterContainerManager *manager;
@property (nonatomic,strong) id<FLBFlutterProvider> viewProvider;
@property (nonatomic, weak, readonly)FlutterViewController * previousViewController;
@property (nonatomic,assign) BOOL isRunning;
@property (nonatomic,strong) NSMutableDictionary *pageResultCallbacks;
@property (nonatomic,strong) NSMutableDictionary *callbackCache;
......@@ -156,6 +158,13 @@
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
result:(NSDictionary *)resultData
exts:(NSDictionary *)exts
......@@ -189,7 +198,7 @@
[newParams setObject:cid?cid:@"__default#0__" forKey:kPageCallBackId];
urlParams = newParams;
}
_previousViewController = [self flutterViewController];
_callbackCache[cid] = resultCallback;
if([urlParams[@"present"]respondsToSelector:@selector(boolValue)] && [urlParams[@"present"] boolValue] && [self.platform respondsToSelector:@selector(present:urlParams:exts:completion:)]){
[self.platform present:url
......
......@@ -97,17 +97,19 @@
arguments:@{@"type":@"foreground"}];
}
- (void)atacheToViewController:(FlutterViewController *)vc
- (BOOL)atacheToViewController:(FlutterViewController *)vc
{
if(_engine.viewController != vc){
// [(FLBFlutterViewContainer *)_engine.viewController surfaceUpdated:NO];
_engine.viewController = vc;
return YES;
}
return NO;
}
- (void)detach
{
if(_engine.viewController != _dummy){
[(FLBFlutterViewContainer *)_engine.viewController surfaceUpdated:NO];
_engine.viewController = _dummy;
}
}
......
......@@ -118,10 +118,6 @@
if(!_name && name){
_name = name;
_params = params;
[BoostMessageChannel didInitPageContainer:^(NSNumber *r) {}
pageName:name
params:params
uniqueId:[self uniqueIDString]];
}
}
......@@ -160,9 +156,38 @@ static NSUInteger kInstanceCounter = 0;
[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
{
[self notifyWillDealloc];
[NSNotificationCenter.defaultCenter removeObserver:self];
}
......@@ -262,11 +287,6 @@ static NSUInteger kInstanceCounter = 0;
pageName:_name
params:_params
uniqueId:self.uniqueIDString];
//如果当前不可见vc和engine所持有的vc一致。在FlutterVC在混合栈中是最后一张页面,如tab中的页面
if (self == FLUTTER_VC)
{
[self surfaceUpdated:NO];
}
[super bridge_viewDidDisappear:animated];
}
......
......@@ -102,7 +102,7 @@ class ContainerCoordinator {
Map map = event;
final String type = map['type'];
Logger.log("onEvent $type");
Logger.log('onEvent $type');
switch (type) {
//Handler back key pressed event.
......@@ -242,7 +242,7 @@ class ContainerCoordinator {
ContainerLifeCycle.Appear);
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;
}
......@@ -275,7 +275,7 @@ class ContainerCoordinator {
FlutterBoost.containerManager?.remove(pageId);
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;
}
......
......@@ -183,9 +183,11 @@ class ContainerManagerState extends State<BoostContainerManager> {
if (SchedulerBinding.instance.schedulerPhase ==
SchedulerPhase.persistentCallbacks) {
SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
Logger.log('_refreshOverlayEntries in addPostFrameCallback');
_refreshOverlayEntries();
});
} else {
Logger.log('_refreshOverlayEntries in setState');
_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