Skip to content

Commit b3a3b99

Browse files
committed
avoid using builders
1 parent e7a9d03 commit b3a3b99

File tree

5 files changed

+572
-592
lines changed

5 files changed

+572
-592
lines changed

app/lib/features/geckoview/features/browser/presentation/screens/browser.dart

Lines changed: 109 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,112 @@ import 'package:weblibre/features/geckoview/features/readerview/presentation/wid
5252
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
5353
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
5454

55+
class _TabBar extends HookConsumerWidget {
56+
final ValueNotifier<bool> showAppBar;
57+
final ValueNotifier<PersistentBottomSheetController?> sheetController;
58+
59+
const _TabBar({required this.showAppBar, required this.sheetController});
60+
61+
@override
62+
Widget build(BuildContext context, WidgetRef ref) {
63+
final tabId = ref.watch(selectedTabProvider);
64+
final displayedSheet = ref.watch(bottomSheetControllerProvider);
65+
66+
final tabInFullScreen = ref.watch(
67+
selectedTabStateProvider.select((value) => value?.isFullScreen ?? false),
68+
);
69+
70+
final autoHideTabBar = ref.watch(
71+
generalSettingsWithDefaultsProvider.select(
72+
(value) => value.autoHideTabBar,
73+
),
74+
);
75+
76+
if (!autoHideTabBar) {
77+
return Visibility(
78+
visible: !tabInFullScreen,
79+
child: BrowserBottomAppBar(displayedSheet: displayedSheet),
80+
);
81+
}
82+
83+
final appBarVisible = useValueListenable(showAppBar);
84+
final diffAcc = useRef(0.0);
85+
86+
void resetHiddenState() {
87+
showAppBar.value = true;
88+
diffAcc.value = 0.0;
89+
}
90+
91+
useEffect(() {
92+
WidgetsBinding.instance.addPostFrameCallback((_) {
93+
resetHiddenState();
94+
});
95+
96+
return null;
97+
}, [tabId]);
98+
99+
useOnAppLifecycleStateChange((previous, current) {
100+
if (current == AppLifecycleState.resumed) {
101+
resetHiddenState();
102+
}
103+
});
104+
105+
ref.listen(tabStateProvider(tabId).select((value) => value?.isLoading), (
106+
previous,
107+
next,
108+
) {
109+
if (next == true) {
110+
resetHiddenState();
111+
}
112+
});
113+
114+
ref.listen(tabStateProvider(tabId).select((value) => value?.historyState), (
115+
previous,
116+
next,
117+
) {
118+
if (next != null && previous != null) {
119+
if (previous != next) {
120+
resetHiddenState();
121+
}
122+
}
123+
});
124+
125+
ref.listen(tabScrollYProvider(tabId, const Duration(milliseconds: 50)), (
126+
previous,
127+
next,
128+
) {
129+
if (previous?.value != null && next.value != null) {
130+
final diff = previous!.value! - next.value!;
131+
if (diff < 0) {
132+
if (diffAcc.value > 0) {
133+
diffAcc.value = 0.0;
134+
}
135+
136+
diffAcc.value += diff;
137+
if (diffAcc.value.abs() > kToolbarHeight * 1.5) {
138+
showAppBar.value = false;
139+
}
140+
} else if (diff > 0) {
141+
if (diffAcc.value < 0) {
142+
diffAcc.value = 0.0;
143+
}
144+
145+
diffAcc.value += diff;
146+
if (diffAcc.value.abs() > (kToolbarHeight / 2)) {
147+
resetHiddenState();
148+
}
149+
}
150+
}
151+
});
152+
153+
return Visibility(
154+
visible:
155+
sheetController.value != null || (!tabInFullScreen && appBarVisible),
156+
child: BrowserBottomAppBar(displayedSheet: displayedSheet),
157+
);
158+
}
159+
}
160+
55161
class BrowserScreen extends HookConsumerWidget {
56162
const BrowserScreen({super.key});
57163

@@ -114,107 +220,9 @@ class BrowserScreen extends HookConsumerWidget {
114220
//This causes issues with a non dismissable barrier pushed, we ahve our own barrier and this does seem to have issues when dismissing, so disable it completely
115221
return null;
116222
},
117-
bottomNavigationBar: HookConsumer(
118-
builder: (context, ref, child) {
119-
final tabId = ref.watch(selectedTabProvider);
120-
final displayedSheet = ref.watch(bottomSheetControllerProvider);
121-
122-
final tabInFullScreen = ref.watch(
123-
selectedTabStateProvider.select(
124-
(value) => value?.isFullScreen ?? false,
125-
),
126-
);
127-
128-
final autoHideTabBar = ref.watch(
129-
generalSettingsWithDefaultsProvider.select(
130-
(value) => value.autoHideTabBar,
131-
),
132-
);
133-
134-
if (!autoHideTabBar) {
135-
return Visibility(
136-
visible: !tabInFullScreen,
137-
child: BrowserBottomAppBar(displayedSheet: displayedSheet),
138-
);
139-
}
140-
141-
final appBarVisible = useValueListenable(showAppBar);
142-
final diffAcc = useRef(0.0);
143-
144-
void resetHiddenState() {
145-
showAppBar.value = true;
146-
diffAcc.value = 0.0;
147-
}
148-
149-
useEffect(() {
150-
WidgetsBinding.instance.addPostFrameCallback((_) {
151-
resetHiddenState();
152-
});
153-
154-
return null;
155-
}, [tabId]);
156-
157-
useOnAppLifecycleStateChange((previous, current) {
158-
if (current == AppLifecycleState.resumed) {
159-
resetHiddenState();
160-
}
161-
});
162-
163-
ref.listen(
164-
tabStateProvider(tabId).select((value) => value?.isLoading),
165-
(previous, next) {
166-
if (next == true) {
167-
resetHiddenState();
168-
}
169-
},
170-
);
171-
172-
ref.listen(
173-
tabStateProvider(tabId).select((value) => value?.historyState),
174-
(previous, next) {
175-
if (next != null && previous != null) {
176-
if (previous != next) {
177-
resetHiddenState();
178-
}
179-
}
180-
},
181-
);
182-
183-
ref.listen(
184-
tabScrollYProvider(tabId, const Duration(milliseconds: 50)),
185-
(previous, next) {
186-
if (previous?.value != null && next.value != null) {
187-
final diff = previous!.value! - next.value!;
188-
if (diff < 0) {
189-
if (diffAcc.value > 0) {
190-
diffAcc.value = 0.0;
191-
}
192-
193-
diffAcc.value += diff;
194-
if (diffAcc.value.abs() > kToolbarHeight * 1.5) {
195-
showAppBar.value = false;
196-
}
197-
} else if (diff > 0) {
198-
if (diffAcc.value < 0) {
199-
diffAcc.value = 0.0;
200-
}
201-
202-
diffAcc.value += diff;
203-
if (diffAcc.value.abs() > (kToolbarHeight / 2)) {
204-
resetHiddenState();
205-
}
206-
}
207-
}
208-
},
209-
);
210-
211-
return Visibility(
212-
visible:
213-
sheetController.value != null ||
214-
(!tabInFullScreen && appBarVisible),
215-
child: BrowserBottomAppBar(displayedSheet: displayedSheet),
216-
);
217-
},
223+
bottomNavigationBar: _TabBar(
224+
showAppBar: showAppBar,
225+
sheetController: sheetController,
218226
),
219227
body: _Browser(
220228
overlayController: overlayController,

0 commit comments

Comments
 (0)