Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Cupertino bottom bar style #1362

Merged
merged 2 commits into from
Jan 14, 2025
Merged
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
3 changes: 2 additions & 1 deletion lib/src/view/analysis/analysis_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ class _BottomBar extends ConsumerWidget {
final ctrlProvider = analysisControllerProvider(options);
final analysisState = ref.watch(ctrlProvider).requireValue;

return BottomBar(
return PlatformBottomBar(
transparentCupertinoBar: false,
children: [
BottomBarButton(
label: context.l10n.menu,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/board_editor/board_editor_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class _BottomBar extends ConsumerWidget {
final editorState = ref.watch(boardEditorControllerProvider(initialFen));
final pieceCount = editorState.pieces.length;

return BottomBar(
return PlatformBottomBar(
children: [
BottomBarButton(
label: context.l10n.menu,
Expand Down
3 changes: 2 additions & 1 deletion lib/src/view/broadcast/broadcast_game_bottom_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class BroadcastGameBottomBar extends ConsumerWidget {
final ctrlProvider = broadcastAnalysisControllerProvider(roundId, gameId);
final broadcastAnalysisState = ref.watch(ctrlProvider).requireValue;

return BottomBar(
return PlatformBottomBar(
transparentCupertinoBar: false,
children: [
BottomBarButton(
label: context.l10n.menu,
Expand Down
7 changes: 4 additions & 3 deletions lib/src/view/broadcast/broadcast_round_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class _BroadcastRoundScreenState extends ConsumerState<BroadcastRoundScreen>
setTournamentId: setTournamentId,
setRoundId: setRoundId,
),
_ => const BottomBar.empty(),
_ => const PlatformBottomBar.empty(transparentCupertinoBar: false),
},
],
),
Expand Down Expand Up @@ -199,7 +199,7 @@ class _BroadcastRoundScreenState extends ConsumerState<BroadcastRoundScreen>
setTournamentId: setTournamentId,
setRoundId: setRoundId,
),
_ => const BottomBar.empty(),
_ => const PlatformBottomBar.empty(transparentCupertinoBar: false),
},
);
}
Expand Down Expand Up @@ -284,7 +284,8 @@ class _BottomBar extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
return BottomBar(
return PlatformBottomBar(
transparentCupertinoBar: false,
children: [
if (tournament.group != null)
AdaptiveTextButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class _BodyState extends ConsumerState<_Body> {
),
),
if (!trainingState.trainingActive)
BottomBar(
PlatformBottomBar(
children: [
BottomBarButton(
label: context.l10n.menu,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class _BodyState extends ConsumerState<_Body> {
),
),
),
BottomBar(
PlatformBottomBar(
children: [
BottomBarButton(
label: context.l10n.flipBoard,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/view/game/archived_game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class _BottomBar extends ConsumerWidget {
final gameData = archivedGameData;

if (gameData == null) {
return const BottomBar(children: []);
return const PlatformBottomBar(children: []);
}

final canGoForward = ref.watch(canGoForwardProvider(gameData.id));
Expand Down Expand Up @@ -283,7 +283,7 @@ class _BottomBar extends ConsumerWidget {
);
}

return BottomBar(
return PlatformBottomBar(
children: [
BottomBarButton(label: context.l10n.menu, onTap: showGameMenu, icon: Icons.menu),
if (gameCursor.hasValue)
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/game/game_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class _GameBottomBar extends ConsumerWidget {
final chatStateAsync =
gamePrefs.enableChat == true ? ref.watch(chatControllerProvider(id)) : null;

return BottomBar(
return PlatformBottomBar(
children: gameStateAsync.when(
data: (gameState) {
final isChatEnabled = chatStateAsync != null && !gameState.isZenModeActive;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/view/game/game_loading_board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LobbyScreenLoadingContent extends StatelessWidget {
),
),
),
BottomBar(
PlatformBottomBar(
children: [
BottomBarButton(
onTap: () async {
Expand Down Expand Up @@ -148,7 +148,7 @@ class ChallengeLoadingContent extends StatelessWidget {
),
),
),
BottomBar(
PlatformBottomBar(
children: [
BottomBarButton(
onTap: () async {
Expand Down Expand Up @@ -258,7 +258,7 @@ class LoadGameError extends StatelessWidget {
),
),
),
BottomBar(
PlatformBottomBar(
children: [
BottomBarButton(
onTap: () => Navigator.of(context).pop(),
Expand Down Expand Up @@ -339,7 +339,7 @@ class ChallengeDeclinedBoard extends StatelessWidget {
),
),
),
BottomBar(
PlatformBottomBar(
children: [
BottomBarButton(
onTap: () => Navigator.of(context).pop(),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/view/opening_explorer/opening_explorer_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ class _BottomBar extends ConsumerWidget {
OpeningDatabase.player => context.l10n.player,
};

return BottomBar(
return PlatformBottomBar(
transparentCupertinoBar: false,
children: [
BottomBarButton(
label: dbLabel,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/over_the_board/over_the_board_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class _BottomBar extends ConsumerWidget {

final clock = ref.watch(overTheBoardClockProvider);

return BottomBar(
return PlatformBottomBar(
children: [
BottomBarButton(
label: 'Configure game',
Expand Down
4 changes: 2 additions & 2 deletions lib/src/view/puzzle/puzzle_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class _LoadPuzzleFromId extends ConsumerWidget {
child: BoardTable.empty(showEngineGaugePlaceholder: true),
),
),
BottomBar.empty(),
PlatformBottomBar.empty(),
],
),
error: (e, s) {
Expand Down Expand Up @@ -346,7 +346,7 @@ class _BottomBar extends ConsumerWidget {
final puzzleState = ref.watch(ctrlProvider);
final isDailyPuzzle = puzzleState.puzzle.isDailyPuzzle == true;

return BottomBar(
return PlatformBottomBar(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
if (initialPuzzleContext.userId != null &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/puzzle/storm_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ class _BottomBar extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final stormState = ref.watch(ctrl);
return BottomBar(
return PlatformBottomBar(
children: [
if (stormState.mode == StormMode.initial)
BottomBarButton(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/puzzle/streak_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class _BottomBar extends ConsumerWidget {
final ctrlProvider = puzzleControllerProvider(initialPuzzleContext, initialStreak: streak);
final puzzleState = ref.watch(ctrlProvider);

return BottomBar(
return PlatformBottomBar(
children: [
if (!puzzleState.streak!.finished)
BottomBarButton(
Expand Down
7 changes: 4 additions & 3 deletions lib/src/view/study/study_bottom_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ class _AnalysisBottomBar extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(studyControllerProvider(id)).valueOrNull;
if (state == null) {
return const BottomBar(children: []);
return const PlatformBottomBar(children: []);
}

final onGoForward =
state.canGoNext ? ref.read(studyControllerProvider(id).notifier).userNext : null;
final onGoBack =
state.canGoBack ? ref.read(studyControllerProvider(id).notifier).userPrevious : null;

return BottomBar(
return PlatformBottomBar(
transparentCupertinoBar: false,
children: [
_ChapterButton(state: state),
_NextChapterButton(
Expand Down Expand Up @@ -90,7 +91,7 @@ class _GamebookBottomBar extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(studyControllerProvider(id)).requireValue;

return BottomBar(
return PlatformBottomBar(
children: [
_ChapterButton(state: state),
...switch (state.gamebookState) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/watch/tv_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class _BottomBar extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
return BottomBar(
return PlatformBottomBar(
children: [
BottomBarButton(
label: context.l10n.flipBoard,
Expand Down
24 changes: 16 additions & 8 deletions lib/src/widgets/bottom_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import 'package:lichess_mobile/src/constants.dart';

/// A container in the style of a bottom app bar, containg a [Row] of children widgets.
///
/// It adapts to the current platform, using a [BottomAppBar] on Android and a [ColoredBox] on iOS.
///
/// The height of the bar is always [kBottomBarHeight].
class BottomBar extends StatelessWidget {
const BottomBar({
class PlatformBottomBar extends StatelessWidget {
const PlatformBottomBar({
required this.children,
this.mainAxisAlignment = MainAxisAlignment.spaceAround,
this.expandChildren = true,
this.transparentCupertinoBar = true,
});

const BottomBar.empty()
const PlatformBottomBar.empty({this.transparentCupertinoBar = true})
: children = const [],
expandChildren = true,
mainAxisAlignment = MainAxisAlignment.spaceAround;
Expand All @@ -26,15 +29,20 @@ class BottomBar extends StatelessWidget {
/// Whether to expand the children to fill the available space. Defaults to true.
final bool expandChildren;

/// Whether to make the Cupertino bar transparent. Defaults to true.
final bool transparentCupertinoBar;

@override
Widget build(BuildContext context) {
if (Theme.of(context).platform == TargetPlatform.iOS) {
return ColoredBox(
color: CupertinoTheme.of(context).barBackgroundColor,
child: SafeArea(
top: false,
child: SizedBox(
height: kBottomBarHeight,
color: CupertinoTheme.of(
context,
).barBackgroundColor.withValues(alpha: transparentCupertinoBar ? 0.0 : null),
child: SizedBox(
height: kBottomBarHeight + MediaQuery.paddingOf(context).bottom,
child: SafeArea(
top: false,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: mainAxisAlignment,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/widgets/bottom_bar_button.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:lichess_mobile/src/widgets/bottom_bar.dart';
import 'package:lichess_mobile/src/widgets/buttons.dart';

/// A bottom bar button.
///
/// Typically used in a [PlatformBottomBar].
class BottomBarButton extends StatelessWidget {
const BottomBarButton({
required this.icon,
Expand Down
Loading