Skip to content

Commit

Permalink
Disable overscroll effect on Android when reduce animations setting i…
Browse files Browse the repository at this point in the history
…s enabled (#839)

* disables overscroll effects on Android when reduce animations setting is on
  • Loading branch information
hjiangsu authored Oct 19, 2023
1 parent 712c3ae commit a9e1505
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Show up to 99 before adding + in the unread count - contribution from @micahmo
- Migrate from old BottomNavigationBar to NavigationBar - contribution from @ggichure
- Adjusted logic to allow for instant switching of sort types, refreshing feed, and switching communities/pages in drawer
- Removed overscroll effect on Android when reduce animation setting is enabled

### Fixed
- Handle issue where failing to retrieve image dimensions blocks post loading - contribution from @Fmstrat
Expand Down
1 change: 0 additions & 1 deletion lib/community/widgets/post_card_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class _PostCardListState extends State<PostCardList> {
}
},
child: MasonryGridView.builder(
physics: reduceAnimations ? const BouncingScrollPhysics() : null,
gridDelegate: tabletMode ? tabletGridDelegate : phoneGridDelegate,
crossAxisSpacing: 40,
mainAxisSpacing: 0,
Expand Down
4 changes: 4 additions & 0 deletions lib/core/theme/bloc/theme_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {

bool useMaterialYouTheme = prefs.getBool(LocalSettings.useMaterialYouTheme.name) ?? false;

// Fetch reduce animations preferences to remove overscrolling effects
bool reduceAnimations = prefs.getBool(LocalSettings.reduceAnimations.name) ?? false;

// Check what the system theme is (light/dark)
Brightness brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness;
bool useDarkTheme = themeType != ThemeType.light;
Expand All @@ -54,6 +57,7 @@ class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
selectedTheme: selectedTheme,
useMaterialYouTheme: useMaterialYouTheme,
useDarkTheme: useDarkTheme,
reduceAnimations: reduceAnimations,
),
);
} catch (e) {
Expand Down
7 changes: 5 additions & 2 deletions lib/core/theme/bloc/theme_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ThemeState extends Equatable {
this.selectedTheme = CustomThemeType.deepBlue,
this.useDarkTheme = false,
this.useMaterialYouTheme = false,
this.reduceAnimations = false,
});

final ThemeStatus status;
Expand All @@ -18,24 +19,26 @@ class ThemeState extends Equatable {
final CustomThemeType selectedTheme;
final bool useDarkTheme;
final bool useMaterialYouTheme;
final bool reduceAnimations;

ThemeState copyWith({
required ThemeStatus status,
ThemeType? themeType,
CustomThemeType? selectedTheme,
bool? useDarkTheme,
bool? useMaterialYouTheme,
ThemeData? darkTheme,
bool? reduceAnimations,
}) {
return ThemeState(
status: status,
themeType: themeType ?? ThemeType.system,
selectedTheme: selectedTheme ?? this.selectedTheme,
useDarkTheme: useDarkTheme ?? false,
useMaterialYouTheme: useMaterialYouTheme ?? false,
reduceAnimations: reduceAnimations ?? false,
);
}

@override
List<Object?> get props => [status, themeType, selectedTheme, useDarkTheme, useMaterialYouTheme];
List<Object?> get props => [status, themeType, selectedTheme, useDarkTheme, useMaterialYouTheme, reduceAnimations];
}
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class ThunderApp extends StatelessWidget {
darkTheme: darkTheme,
debugShowCheckedModeBanner: false,
scaffoldMessengerKey: GlobalContext.scaffoldMessengerKey,
scrollBehavior: (state.reduceAnimations && Platform.isAndroid) ? const ScrollBehavior().copyWith(overscroll: false) : null,
),
);
},
Expand Down
1 change: 0 additions & 1 deletion lib/post/widgets/comment_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class _CommentSubviewState extends State<CommentSubview> with SingleTickerProvid
}
},
child: ScrollablePositionedList.builder(
physics: reduceAnimations ? const BouncingScrollPhysics() : null,
addSemanticIndexes: false,
itemScrollController: widget.itemScrollController,
itemPositionsListener: widget.itemPositionsListener,
Expand Down
2 changes: 2 additions & 0 deletions lib/settings/pages/accessibility_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'package:thunder/core/enums/local_settings.dart';
import 'package:thunder/core/singletons/preferences.dart';
import 'package:thunder/core/theme/bloc/theme_bloc.dart';
import 'package:thunder/settings/widgets/accessibility_profile.dart';
import 'package:thunder/settings/widgets/toggle_option.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
Expand All @@ -27,6 +28,7 @@ class _AccessibilitySettingsPageState extends State<AccessibilitySettingsPage> w
case LocalSettings.reduceAnimations:
await prefs.setBool(LocalSettings.reduceAnimations.name, value);
setState(() => reduceAnimations = value);
if (context.mounted) context.read<ThemeBloc>().add(ThemeChangeEvent());
break;
}

Expand Down

0 comments on commit a9e1505

Please sign in to comment.