Skip to content

Commit 609e1eb

Browse files
committed
[ohos]解决从透明弹窗返回后页面假死的问题
NavDestinationMode.DIALOG:默认透明,进出页面栈不影响下层NavDestination的生命周期,不支持系统转场动画
1 parent 7c957c5 commit 609e1eb

12 files changed

+156
-137
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## NEXT
22
1. [ohos]接管FlutterView绑定引擎的时机,解决Tab场景显示异常的问题,避免冗余的attach/detach
3+
2. [ohos]解决从透明弹窗返回后页面假死的问题
34

45
# 4.5.5
56
1. [ohos]修复image_pick插件示例

example/lib/case/media_query.dart

+47-51
Original file line numberDiff line numberDiff line change
@@ -56,57 +56,53 @@ class _MediaQueryRouteWidgetState extends State<MediaQueryRouteWidget> {
5656
appBar: AppBar(
5757
title: const Text('media query demo'),
5858
),
59-
body: Column(
60-
crossAxisAlignment: CrossAxisAlignment.start,
61-
children: <Widget>[
62-
Expanded(
63-
flex: 2,
64-
child: Container(
65-
margin: const EdgeInsets.all(24.0),
66-
child: Column(
67-
crossAxisAlignment: CrossAxisAlignment.start,
68-
children: <Widget>[
69-
Text('top: ${MediaQuery.of(context).padding.top}'),
70-
Text(
71-
'bottom: ${MediaQuery.of(context).padding.bottom}'),
72-
Text('width: ${MediaQuery.of(context).size.width}'),
73-
Text('height: ${MediaQuery.of(context).size.height}')
74-
]))),
75-
Expanded(
76-
flex: 1,
77-
child: Column(
78-
mainAxisAlignment: MainAxisAlignment.end,
79-
crossAxisAlignment: CrossAxisAlignment.start,
80-
children: <Widget>[
81-
InkWell(
82-
child: Container(
83-
padding: const EdgeInsets.all(8.0),
84-
margin: const EdgeInsets.all(8.0),
85-
color: Colors.yellow,
86-
child: const Text(
87-
'Pop with Navigator',
88-
style:
89-
TextStyle(fontSize: 22.0, color: Colors.black),
90-
)),
91-
onTap: () => Navigator.of(context).pop(
92-
'I am Navigator from MediaQueryRouteWidget too!'),
93-
),
94-
InkWell(
95-
child: Container(
96-
padding: const EdgeInsets.all(8.0),
97-
margin: const EdgeInsets.all(8.0),
98-
color: Colors.yellow,
99-
child: const Text(
100-
'Pop with BoostNavigator',
101-
style:
102-
TextStyle(fontSize: 22.0, color: Colors.black),
103-
)),
104-
onTap: () => BoostNavigator.instance.pop(
105-
'I am BoostNavigator from MediaQueryRouteWidget!'),
106-
),
107-
]),
108-
),
109-
]),
59+
body: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <
60+
Widget>[
61+
Expanded(
62+
flex: 2,
63+
child: Container(
64+
margin: const EdgeInsets.all(24.0),
65+
child: Column(
66+
crossAxisAlignment: CrossAxisAlignment.start,
67+
children: <Widget>[
68+
Text('top: ${MediaQuery.of(context).padding.top}'),
69+
Text('bottom: ${MediaQuery.of(context).padding.bottom}'),
70+
Text('width: ${MediaQuery.of(context).size.width}'),
71+
Text('height: ${MediaQuery.of(context).size.height}')
72+
]))),
73+
Expanded(
74+
flex: 1,
75+
child: Column(
76+
mainAxisAlignment: MainAxisAlignment.end,
77+
crossAxisAlignment: CrossAxisAlignment.start,
78+
children: <Widget>[
79+
InkWell(
80+
child: Container(
81+
padding: const EdgeInsets.all(8.0),
82+
margin: const EdgeInsets.all(8.0),
83+
color: Colors.yellow,
84+
child: const Text(
85+
'Pop with Navigator',
86+
style: TextStyle(fontSize: 22.0, color: Colors.black),
87+
)),
88+
onTap: () => Navigator.of(context)
89+
.pop('I am Navigator from MediaQueryRouteWidget too!'),
90+
),
91+
InkWell(
92+
child: Container(
93+
padding: const EdgeInsets.all(8.0),
94+
margin: const EdgeInsets.all(8.0),
95+
color: Colors.yellow,
96+
child: const Text(
97+
'Pop with BoostNavigator',
98+
style: TextStyle(fontSize: 22.0, color: Colors.black),
99+
)),
100+
onTap: () => BoostNavigator.instance
101+
.pop('I am BoostNavigator from MediaQueryRouteWidget!'),
102+
),
103+
]),
104+
),
105+
]),
110106
);
111107
}
112108
}

example/lib/case/native_view.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class NativeView extends StatelessWidget {
2626
surfaceFactory: (context, controller) {
2727
return AndroidViewSurface(
2828
controller: controller as AndroidViewController,
29-
gestureRecognizers: const <Factory<
30-
OneSequenceGestureRecognizer>>{},
29+
gestureRecognizers: const <
30+
Factory<OneSequenceGestureRecognizer>>{},
3131
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
3232
);
3333
},

example/lib/case/safe_area.dart

+62-62
Original file line numberDiff line numberDiff line change
@@ -15,69 +15,69 @@ class _SafeAreaPageState extends State<SafeAreaPage> {
1515
return MaterialApp(
1616
home: Scaffold(
1717
body: SafeArea(
18-
top: top,
19-
left: true,
20-
bottom: bottom,
21-
right: true,
22-
minimum: const EdgeInsets.all(1.0),
23-
child: Stack(
24-
children: <Widget>[
25-
Column(
26-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
27-
children: [
28-
Text(
29-
'This is an example explaining use of SafeArea.',
30-
style: TextStyle(color: Colors.green, fontSize: 18),
31-
),
32-
Text(
33-
'This is an example explaining use of SafeArea.',
34-
style: TextStyle(color: Colors.green, fontSize: 18),
35-
),
36-
]),
37-
Column(
38-
mainAxisAlignment: MainAxisAlignment.center,
39-
crossAxisAlignment: CrossAxisAlignment.start,
40-
children: [
41-
Row(
42-
mainAxisAlignment: MainAxisAlignment.end,
18+
top: top,
19+
left: true,
20+
bottom: bottom,
21+
right: true,
22+
minimum: const EdgeInsets.all(1.0),
23+
child: Stack(
24+
children: <Widget>[
25+
Column(
26+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
4327
children: [
44-
const Text('SafeArea: top'),
45-
Switch(
46-
value: top,
47-
onChanged: (bool value) {
48-
setState(() {
49-
top = value;
50-
});
51-
}),
52-
],
53-
),
54-
Row(
55-
mainAxisAlignment: MainAxisAlignment.end,
56-
children: [
57-
const Text('SafeArea: bottom'),
58-
Switch(
59-
value: bottom,
60-
onChanged: (bool value) {
61-
setState(() {
62-
bottom = value;
63-
});
64-
}),
65-
],
66-
),
67-
Column(
68-
crossAxisAlignment: CrossAxisAlignment.start,
69-
children: [
70-
Text('top: ${MediaQuery.of(context).padding.top}'),
71-
Text('bottom: ${MediaQuery.of(context).padding.bottom}'),
72-
Text('width: ${MediaQuery.of(context).size.width}'),
73-
Text('height: ${MediaQuery.of(context).size.height}'),
74-
],
75-
),
76-
],
77-
),
78-
],
79-
)
80-
),
28+
Text(
29+
'This is an example explaining use of SafeArea.',
30+
style: TextStyle(color: Colors.green, fontSize: 18),
31+
),
32+
Text(
33+
'This is an example explaining use of SafeArea.',
34+
style: TextStyle(color: Colors.green, fontSize: 18),
35+
),
36+
]),
37+
Column(
38+
mainAxisAlignment: MainAxisAlignment.center,
39+
crossAxisAlignment: CrossAxisAlignment.start,
40+
children: [
41+
Row(
42+
mainAxisAlignment: MainAxisAlignment.end,
43+
children: [
44+
const Text('SafeArea: top'),
45+
Switch(
46+
value: top,
47+
onChanged: (bool value) {
48+
setState(() {
49+
top = value;
50+
});
51+
}),
52+
],
53+
),
54+
Row(
55+
mainAxisAlignment: MainAxisAlignment.end,
56+
children: [
57+
const Text('SafeArea: bottom'),
58+
Switch(
59+
value: bottom,
60+
onChanged: (bool value) {
61+
setState(() {
62+
bottom = value;
63+
});
64+
}),
65+
],
66+
),
67+
Column(
68+
crossAxisAlignment: CrossAxisAlignment.start,
69+
children: [
70+
Text('top: ${MediaQuery.of(context).padding.top}'),
71+
Text(
72+
'bottom: ${MediaQuery.of(context).padding.bottom}'),
73+
Text('width: ${MediaQuery.of(context).size.width}'),
74+
Text('height: ${MediaQuery.of(context).size.height}'),
75+
],
76+
),
77+
],
78+
),
79+
],
80+
)),
8181
),
8282
);
8383
}

example/lib/case/webview_flutter_demo.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class _WebViewExampleState extends State<WebViewExample> {
100100
allowsInlineMediaPlayback: true,
101101
mediaTypesRequiringUserAction: const <PlaybackMediaTypes>{},
102102
);
103-
} if (WebViewPlatform.instance is OhosWebViewPlatform) {
103+
}
104+
if (WebViewPlatform.instance is OhosWebViewPlatform) {
104105
params = OhosWebViewControllerCreationParams();
105106
} else {
106107
params = const PlatformWebViewControllerCreationParams();

example/lib/flutter_page.dart

+10-10
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,16 @@ class _FlutterIndexRouteState extends State<FlutterIndexRoute>
245245
onTap: () => BoostNavigator.instance
246246
.push('hero_animation', withContainer: withContainer)),
247247
InkWell(
248-
child: Container(
249-
padding: const EdgeInsets.all(8.0),
250-
margin: const EdgeInsets.all(8.0),
251-
color: Colors.yellow,
252-
child: const Text(
253-
'SafeArea demo',
254-
style: TextStyle(fontSize: 22.0, color: Colors.black),
255-
)),
256-
onTap: () => BoostNavigator.instance
257-
.push("safe_area", withContainer: withContainer)),
248+
child: Container(
249+
padding: const EdgeInsets.all(8.0),
250+
margin: const EdgeInsets.all(8.0),
251+
color: Colors.yellow,
252+
child: const Text(
253+
'SafeArea demo',
254+
style: TextStyle(fontSize: 22.0, color: Colors.black),
255+
)),
256+
onTap: () => BoostNavigator.instance
257+
.push("safe_area", withContainer: withContainer)),
258258
InkWell(
259259
child: Container(
260260
padding: const EdgeInsets.all(8.0),

example/lib/main.dart

+1
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ class _MyAppState extends State<MyApp> {
390390
settings: settings,
391391
pageBuilder: (_, __, ___) => const SafeAreaPage());
392392
},
393+
393394
///使用 BoostCacheWidget包裹你的页面时,可以解决push pageA->pageB->pageC 过程中,pageA,pageB 会多次 rebuild 的问题
394395
'flutterRebuildDemo': (settings, uniqueId) {
395396
return MaterialPageRoute(

example/ohos/entry/src/main/ets/pages/FlutterUIDialog.ets

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* THE SOFTWARE.
2323
*/
2424

25+
import Curves from '@ohos.curves'
2526
import hilog from '@ohos.hilog';
2627
import { FlutterBoostEntry } from 'flutter_boost';
2728
import { FlutterPage, FlutterView } from '@ohos/flutter_ohos';
@@ -33,10 +34,13 @@ export struct FlutterUIDialog {
3334
private flutterEntry: FlutterBoostEntry | null = null;
3435
private flutterView: FlutterView | null = null;
3536
@Prop xComponentType: XComponentType = XComponentType.SURFACE;
37+
private effect: object =
38+
TransitionEffect.OPACITY
39+
.combine(TransitionEffect.move(TransitionEdge.BOTTOM)).animation({curve: Curves.springMotion()});
3640

3741
aboutToAppear() {
3842
hilog.info(0x0000, TAG, "aboutToAppear===");
39-
this.flutterEntry = new FlutterBoostEntry(getContext(this));
43+
this.flutterEntry = new FlutterBoostEntry(getContext(this), {}, /*isDialog*/true);
4044
this.flutterEntry.aboutToAppear();
4145
// The |aboutToAppear| method is called first,
4246
// followed by the |getFlutterView| method.
@@ -78,5 +82,6 @@ export struct FlutterUIDialog {
7882
hilog.error(0x0000, TAG, `onReady catch exception: ${JSON.stringify(e)}`);
7983
}
8084
})
85+
.transition(this.effect)
8186
}
8287
}

example/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import FlutterEngine from '@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine';
2-
import Log from '@ohos/flutter_ohos/src/main/ets/util/Log';
3-
import FlutterBoostPlugin from '@ohos/flutter_boost'
4-
import ImagePickerPlugin from '@ohos/image_picker_ohos'
5-
import PathProviderPlugin from '@ohos/path_provider_ohos'
6-
import VideoPlayerPlugin from '@ohos/video_player_ohos'
7-
import WebViewFlutterPlugin from '@ohos/webview_flutter_ohos'
1+
import { FlutterEngine, Log } from '@ohos/flutter_ohos';
2+
import FlutterBoostPlugin from 'flutter_boost';
3+
import ImagePickerPlugin from 'image_picker_ohos';
4+
import PathProviderPlugin from 'path_provider_ohos';
5+
import VideoPlayerPlugin from 'video_player_ohos';
6+
import WebViewFlutterPlugin from 'webview_flutter_ohos';
87

98
/**
109
* Generated file. Do not edit.

ohos/flutter_boost/src/main/ets/components/containers/FlutterBoostAbility.ets

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ export default class FlutterBoostAbility extends FlutterAbility implements Flutt
148148
throw new Error('Method not implemented.');
149149
}
150150

151+
attachToEngineIfNeeded(): void {
152+
throw new Error('Method not implemented.');
153+
}
154+
151155
detachFromEngineIfNeeded() {
152156
this.performDetach()
153157
}

0 commit comments

Comments
 (0)