Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/app_flavored.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FlavoredAppState extends ConsumerState<FlavoredApp> {
builder: (overrideLocale) => Builder(
builder: (context) => MaterialApp(
scaffoldMessengerKey: Keys.scaffoldMessengerStateKey,
navigatorObservers: [routeObserver],
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: RouterF.routes,
Expand Down
1 change: 1 addition & 0 deletions lib/app_opener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class OpenerApp extends ConsumerWidget {
child: OverrideLocale(
builder: (overrideLocale) => MaterialApp(
navigatorKey: Keys.navigatorKey,
navigatorObservers: [routeObserver],
scaffoldMessengerKey: Keys.scaffoldMessengerStateKey,
debugShowCheckedModeBanner: false,
initialRoute: AppRouter.initRoute,
Expand Down
25 changes: 24 additions & 1 deletion lib/flavored/web_view.f.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ class WebViewF extends ConsumerStatefulWidget {
FlavoredWebViewState createState() => FlavoredWebViewState();
}

class FlavoredWebViewState extends ConsumerState<WebViewF> {
class FlavoredWebViewState extends ConsumerState<WebViewF> with RouteAware {
HeadlessInAppWebView? headlessWebView;
late HumHubF instance;
final _scaffoldKey = GlobalKey<ScaffoldState>();
late PullToRefreshController pullToRefreshController;
late double downloadProgress = 0;
bool _isRouteObserverSubscribed = false;

@override
void initState() {
Expand All @@ -62,6 +63,27 @@ class FlavoredWebViewState extends ConsumerState<WebViewF> {
);
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
if (!_isRouteObserverSubscribed) {
routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute);
_isRouteObserverSubscribed = true;
}
}

/// Called when a route pushed on top of WebViewF (e.g. AuthWebView) is popped.
/// That screen locks orientation to portrait, and since popping back doesn't
/// re-run WebViewF's own route builder, the lock would otherwise persist.
@override
void didPopNext() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}

@override
Widget build(BuildContext context) {
ref.watch(humHubFRemoteConfigProvider);
Expand Down Expand Up @@ -435,6 +457,7 @@ class FlavoredWebViewState extends ConsumerState<WebViewF> {

@override
void dispose() {
routeObserver.unsubscribe(this);
super.dispose();
if (headlessWebView != null) {
headlessWebView!.dispose();
Expand Down
18 changes: 17 additions & 1 deletion lib/pages/web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class WebView extends ConsumerStatefulWidget {
WebViewAppState createState() => WebViewAppState();
}

class WebViewAppState extends ConsumerState<WebView> {
class WebViewAppState extends ConsumerState<WebView> with RouteAware {
final _scaffoldKey = GlobalKey<ScaffoldState>();
late Manifest _manifest;
late URLRequest _initialRequest;
Expand Down Expand Up @@ -88,10 +88,25 @@ class WebViewAppState extends ConsumerState<WebView> {
headers: ref.read(humHubProvider).customHeaders));
},
);
routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute);
_isInit = true;
}
}

/// Called when a route pushed on top of WebView (e.g. Settings, Console, Help,
/// AuthWebView) is popped. Those screens lock orientation to portrait, and since
/// popping back doesn't re-run WebView's own route builder, the lock would
/// otherwise persist indefinitely.
@override
void didPopNext() {
logInfo('VERIFY_PROBE: WebView.didPopNext firing, restoring landscape+portrait orientation');
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -592,6 +607,7 @@ class WebViewAppState extends ConsumerState<WebView> {
logInfo('Disposing WebView and controllers');
if (_headlessWebView != null) _headlessWebView!.dispose();
_keyboardSubscription?.cancel();
routeObserver.unsubscribe(this);
super.dispose();
}
}
4 changes: 4 additions & 0 deletions lib/util/const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class Keys{
static GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
}

/// Notifies [RouteAware] pages (e.g. WebView) when a route pushed on top of them is popped,
/// so they can restore orientation/UI state that the popped route may have overridden.
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();

class Assets {
static String logo = "assets/images/logo.png";
static String settings = "assets/images/icons/settings.svg";
Expand Down