From ab1e90ccad53f95ef8262d56373f0a1257a96af2 Mon Sep 17 00:00:00 2001 From: Jiaqi Feng Date: Sun, 26 Mar 2023 19:16:38 -0700 Subject: [PATCH] fix comment tile and bottom navigation bar. (#187) --- android/app/build.gradle | 2 +- ios/Podfile.lock | 6 +++ lib/cubits/comments/comments_cubit.dart | 6 --- lib/extensions/context_extension.dart | 4 -- lib/extensions/state_extension.dart | 10 +++-- lib/main.dart | 29 ++++++++++---- lib/screens/home/home_screen.dart | 15 +++---- lib/screens/item/item_screen.dart | 26 ++++-------- lib/screens/item/widgets/custom_app_bar.dart | 24 +++++------ lib/screens/item/widgets/more_popup_menu.dart | 4 +- lib/screens/widgets/comment_tile.dart | 9 ----- lib/screens/widgets/item_text.dart | 40 +++++++++---------- pubspec.lock | 30 ++++++++++---- pubspec.yaml | 11 ++--- submodules/flutter | 2 +- 15 files changed, 110 insertions(+), 108 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 17a664b..0eefe07 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -50,7 +50,7 @@ android { defaultConfig { applicationId "com.jiaqifeng.hacki" - minSdkVersion 30 + minSdkVersion 26 targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 544a530..0cfee95 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -2,6 +2,8 @@ PODS: - connectivity_plus (0.0.1): - Flutter - ReachabilitySwift + - device_info_plus (0.0.1): + - Flutter - Flutter (1.0.0) - flutter_email_sender (0.0.1): - Flutter @@ -53,6 +55,7 @@ PODS: DEPENDENCIES: - connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`) + - device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) - Flutter (from `Flutter`) - flutter_email_sender (from `.symlinks/plugins/flutter_email_sender/ios`) - flutter_inappwebview (from `.symlinks/plugins/flutter_inappwebview/ios`) @@ -81,6 +84,8 @@ SPEC REPOS: EXTERNAL SOURCES: connectivity_plus: :path: ".symlinks/plugins/connectivity_plus/ios" + device_info_plus: + :path: ".symlinks/plugins/device_info_plus/ios" Flutter: :path: Flutter flutter_email_sender: @@ -120,6 +125,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e + device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 flutter_email_sender: 02d7443217d8c41483223627972bfdc09f74276b flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721 diff --git a/lib/cubits/comments/comments_cubit.dart b/lib/cubits/comments/comments_cubit.dart index d5d46b4..bdd6018 100644 --- a/lib/cubits/comments/comments_cubit.dart +++ b/lib/cubits/comments/comments_cubit.dart @@ -26,7 +26,6 @@ class CommentsCubit extends Cubit { StoriesRepository? storiesRepository, SembastRepository? sembastRepository, Logger? logger, - required bool isScreenReaderEnabled, required bool isOfflineReading, required Item item, required FetchMode defaultFetchMode, @@ -40,7 +39,6 @@ class CommentsCubit extends Cubit { _sembastRepository = sembastRepository ?? locator.get(), _logger = logger ?? locator.get(), - _isScreenReaderEnabled = isScreenReaderEnabled, super( CommentsState.init( isOfflineReading: isOfflineReading, @@ -56,7 +54,6 @@ class CommentsCubit extends Cubit { final StoriesRepository _storiesRepository; final SembastRepository _sembastRepository; final Logger _logger; - final bool _isScreenReaderEnabled; /// The [StreamSubscription] for stream (both lazy or eager) /// fetching comments posted directly to the story. @@ -359,9 +356,6 @@ class CommentsCubit extends Cubit { emit(state.copyWith(comments: updatedComments)); if (state.fetchMode == FetchMode.eager) { - /// If screen reader is on, fetch all the comments without paging. - if (_isScreenReaderEnabled) return; - if (updatedComments.length >= _pageSize + _pageSize * state.currentPage && updatedComments.length <= diff --git a/lib/extensions/context_extension.dart b/lib/extensions/context_extension.dart index 9711c63..d656f8c 100644 --- a/lib/extensions/context_extension.dart +++ b/lib/extensions/context_extension.dart @@ -6,8 +6,6 @@ import 'package:hacki/config/constants.dart'; import 'package:hacki/styles/styles.dart'; extension ContextExtension on BuildContext { - bool get isScreenReaderEnabled => MediaQuery.of(this).accessibleNavigation; - T? tryRead() { try { return read(); @@ -21,8 +19,6 @@ extension ContextExtension on BuildContext { VoidCallback? action, String? label, }) { - if (isScreenReaderEnabled) return; - ScaffoldMessenger.of(this).showSnackBar( SnackBar( backgroundColor: Palette.deepOrange, diff --git a/lib/extensions/state_extension.dart b/lib/extensions/state_extension.dart index 7a878ba..e63a00f 100644 --- a/lib/extensions/state_extension.dart +++ b/lib/extensions/state_extension.dart @@ -58,10 +58,12 @@ extension StateExtension on State { context: context, isScrollControlled: true, builder: (BuildContext context) { - return MorePopupMenu( - item: item, - isBlocked: isBlocked, - onLoginTapped: onLoginTapped, + return SafeArea( + child: MorePopupMenu( + item: item, + isBlocked: isBlocked, + onLoginTapped: onLoginTapped, + ), ); }, ).then((MenuAction? action) { diff --git a/lib/main.dart b/lib/main.dart index ffdee3e..39e3e4e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'package:adaptive_theme/adaptive_theme.dart'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:equatable/equatable.dart'; import 'package:feature_discovery/feature_discovery.dart'; import 'package:flutter/foundation.dart'; @@ -110,13 +111,27 @@ Future main({bool testing = false}) async { }, ); } else if (Platform.isAndroid) { - SystemChrome.setSystemUIOverlayStyle( - const SystemUiOverlayStyle( - statusBarColor: Palette.transparent, - systemNavigationBarColor: Palette.transparent, - systemNavigationBarDividerColor: Palette.transparent, - ), - ); + final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin(); + final AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo; + final int sdk = androidInfo.version.sdkInt; + + if (sdk > 28) { + SystemChrome.setSystemUIOverlayStyle( + const SystemUiOverlayStyle( + statusBarColor: Palette.transparent, + systemNavigationBarColor: Palette.transparent, + systemNavigationBarDividerColor: Palette.transparent, + ), + ); + } else { + SystemChrome.setSystemUIOverlayStyle( + const SystemUiOverlayStyle( + statusBarBrightness: Brightness.light, + statusBarIconBrightness: Brightness.dark, + statusBarColor: Colors.transparent, + ), + ); + } await SystemChrome.setEnabledSystemUIMode( SystemUiMode.edgeToEdge, diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index ce5b81a..92e7802 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -92,14 +92,12 @@ class _HomeScreenState extends State SchedulerBinding.instance ..addPostFrameCallback((_) { - if (context.isScreenReaderEnabled == false) { - FeatureDiscovery.discoverFeatures( - context, - { - Constants.featureLogIn, - }, - ); - } + FeatureDiscovery.discoverFeatures( + context, + { + Constants.featureLogIn, + }, + ); }) ..addPostFrameCallback((_) { final ModalRoute? route = ModalRoute.of(context); @@ -229,7 +227,6 @@ class _HomeScreenState extends State } else { final ItemScreenArgs args = ItemScreenArgs( item: story, - isScreenReaderEnabled: context.isScreenReaderEnabled, ); context.read().updateLastReadStoryId(story.id); diff --git a/lib/screens/item/item_screen.dart b/lib/screens/item/item_screen.dart index 832021a..4324bb1 100644 --- a/lib/screens/item/item_screen.dart +++ b/lib/screens/item/item_screen.dart @@ -23,13 +23,11 @@ class ItemScreenArgs extends Equatable { required this.item, this.onlyShowTargetComment = false, this.useCommentCache = false, - this.isScreenReaderEnabled = false, this.targetComments, }); final Item item; final bool onlyShowTargetComment; - final bool isScreenReaderEnabled; final List? targetComments; /// when a user is trying to view a sub-thread from a main thread, we don't @@ -41,7 +39,6 @@ class ItemScreenArgs extends Equatable { List get props => [ item, onlyShowTargetComment, - isScreenReaderEnabled, targetComments, useCommentCache, ]; @@ -75,7 +72,6 @@ class ItemScreen extends StatefulWidget { context.read().state.fetchMode, defaultCommentsOrder: context.read().state.order, - isScreenReaderEnabled: args.isScreenReaderEnabled, )..init( onlyShowTargetComment: args.onlyShowTargetComment, targetAncestors: args.targetComments, @@ -118,7 +114,6 @@ class ItemScreen extends StatefulWidget { context.read().state.fetchMode, defaultCommentsOrder: context.read().state.order, - isScreenReaderEnabled: args.isScreenReaderEnabled, )..init( onlyShowTargetComment: args.onlyShowTargetComment, targetAncestors: args.targetComments, @@ -178,16 +173,14 @@ class _ItemScreenState extends State with RouteAware { SchedulerBinding.instance ..addPostFrameCallback((_) { - if (context.isScreenReaderEnabled == false) { - FeatureDiscovery.discoverFeatures( - context, - { - Constants.featurePinToTop, - Constants.featureAddStoryToFavList, - Constants.featureOpenStoryInWebView, - }, - ); - } + FeatureDiscovery.discoverFeatures( + context, + { + Constants.featurePinToTop, + Constants.featureAddStoryToFavList, + Constants.featureOpenStoryInWebView, + }, + ); }) ..addPostFrameCallback((_) { final ModalRoute? route = ModalRoute.of(context); @@ -325,8 +318,6 @@ class _ItemScreenState extends State with RouteAware { context.read().zoom, onFontSizeTap: onFontSizeTapped, fontSizeIconButtonKey: fontSizeIconButtonKey, - isScreenReaderEnabled: - context.isScreenReaderEnabled, ), ); }, @@ -362,7 +353,6 @@ class _ItemScreenState extends State with RouteAware { scrollController: scrollController, onFontSizeTap: onFontSizeTapped, fontSizeIconButtonKey: fontSizeIconButtonKey, - isScreenReaderEnabled: context.isScreenReaderEnabled, ), body: MainView( scrollController: scrollController, diff --git a/lib/screens/item/widgets/custom_app_bar.dart b/lib/screens/item/widgets/custom_app_bar.dart index a0eec5f..adb26f1 100644 --- a/lib/screens/item/widgets/custom_app_bar.dart +++ b/lib/screens/item/widgets/custom_app_bar.dart @@ -16,7 +16,6 @@ class CustomAppBar extends AppBar { bool splitViewEnabled = false, VoidCallback? onZoomTap, bool? expanded, - bool isScreenReaderEnabled = false, }) : super( elevation: Dimens.zero, actions: [ @@ -38,20 +37,19 @@ class CustomAppBar extends AppBar { ScrollUpIconButton( scrollController: scrollController, ), - if (isScreenReaderEnabled == false) - IconButton( - key: fontSizeIconButtonKey, - icon: Text( - String.fromCharCode(FeatherIcons.type.codePoint), - style: TextStyle( - fontWeight: FontWeight.w800, - fontSize: TextDimens.pt18, - fontFamily: FeatherIcons.type.fontFamily, - package: FeatherIcons.type.fontPackage, - ), + IconButton( + key: fontSizeIconButtonKey, + icon: Text( + String.fromCharCode(FeatherIcons.type.codePoint), + style: TextStyle( + fontWeight: FontWeight.w800, + fontSize: TextDimens.pt18, + fontFamily: FeatherIcons.type.fontFamily, + package: FeatherIcons.type.fontPackage, ), - onPressed: onFontSizeTap, ), + onPressed: onFontSizeTap, + ), if (item is Story) PinIconButton( story: item, diff --git a/lib/screens/item/widgets/more_popup_menu.dart b/lib/screens/item/widgets/more_popup_menu.dart index b43c3c6..7bfb5da 100644 --- a/lib/screens/item/widgets/more_popup_menu.dart +++ b/lib/screens/item/widgets/more_popup_menu.dart @@ -23,8 +23,8 @@ class MorePopupMenu extends StatelessWidget { final bool isBlocked; final VoidCallback onLoginTapped; - static const double _storySheetHeight = 500; - static const double _commentSheetHeight = 480; + static const double _storySheetHeight = 485; + static const double _commentSheetHeight = 470; @override Widget build(BuildContext context) { diff --git a/lib/screens/widgets/comment_tile.dart b/lib/screens/widgets/comment_tile.dart index 4b708b7..2c70171 100644 --- a/lib/screens/widgets/comment_tile.dart +++ b/lib/screens/widgets/comment_tile.dart @@ -70,7 +70,6 @@ class CommentTile extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Slidable( - enabled: context.isScreenReaderEnabled == false, startActionPane: actionable ? ActionPane( motion: const StretchMotion(), @@ -118,14 +117,6 @@ class CommentTile extends StatelessWidget { : null, child: InkWell( onTap: () { - if (context.isScreenReaderEnabled) { - onMoreTapped?.call( - comment, - context.rect, - ); - return; - } - if (actionable) { HapticFeedback.selectionClick(); context.read().collapse(); diff --git a/lib/screens/widgets/item_text.dart b/lib/screens/widgets/item_text.dart index f780239..3ad1b4f 100644 --- a/lib/screens/widgets/item_text.dart +++ b/lib/screens/widgets/item_text.dart @@ -38,17 +38,15 @@ class ItemText extends StatelessWidget { ), onTap: onTap, textScaleFactor: MediaQuery.of(context).textScaleFactor, - contextMenuBuilder: context.isScreenReaderEnabled - ? null - : ( - BuildContext context, - EditableTextState editableTextState, - ) => - contextMenuBuilder( - context, - editableTextState, - item: item, - ), + contextMenuBuilder: ( + BuildContext context, + EditableTextState editableTextState, + ) => + contextMenuBuilder( + context, + editableTextState, + item: item, + ), semanticsLabel: item.text, ); } else { @@ -59,17 +57,15 @@ class ItemText extends StatelessWidget { linkStyle: linkStyle, onOpen: (LinkableElement link) => LinkUtil.launch(link.url), onTap: onTap, - contextMenuBuilder: context.isScreenReaderEnabled - ? null - : ( - BuildContext context, - EditableTextState editableTextState, - ) => - contextMenuBuilder( - context, - editableTextState, - item: item, - ), + contextMenuBuilder: ( + BuildContext context, + EditableTextState editableTextState, + ) => + contextMenuBuilder( + context, + editableTextState, + item: item, + ), semanticsLabel: item.text, ); } diff --git a/pubspec.lock b/pubspec.lock index 2a00b4a..9ea4b08 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -13,10 +13,10 @@ packages: dependency: "direct main" description: name: adaptive_theme - sha256: "84af26cfc68220df3cd35d9d94cb8953e7182ef560e13d8efb87f32bf1e588fc" + sha256: "61bde10390e937d11d05c6cf0d5cf378a73d49f9a442262e43613dae60ed0b3f" url: "https://pub.dev" source: hosted - version: "3.1.1" + version: "3.2.0" analyzer: dependency: transitive description: @@ -201,6 +201,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.8" + device_info_plus: + dependency: "direct main" + description: + name: device_info_plus + sha256: "1d6e5a61674ba3a68fb048a7c7b4ff4bebfed8d7379dbe8f2b718231be9a7c95" + url: "https://pub.dev" + source: hosted + version: "8.1.0" + device_info_plus_platform_interface: + dependency: transitive + description: + name: device_info_plus_platform_interface + sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64 + url: "https://pub.dev" + source: hosted + version: "7.0.0" diff_match_patch: dependency: transitive description: @@ -213,10 +229,10 @@ packages: dependency: "direct main" description: name: dio - sha256: "7d328c4d898a61efc3cd93655a0955858e29a0aa647f0f9e02d59b3bb275e2e8" + sha256: "3e5c4a94d112540d0c9a6b7f3969832e1604eb8cde0f88d0808382f9f632100b" url: "https://pub.dev" source: hosted - version: "4.0.6" + version: "5.0.3" equatable: dependency: "direct main" description: @@ -572,10 +588,10 @@ packages: dependency: "direct main" description: name: logger - sha256: "5076f09225f91dc49289a4ccb92df2eeea9ea01cf7c26d49b3a1f04c6a49eec1" + sha256: db2ff852ed77090ba9f62d3611e4208a3d11dfa35991a81ae724c113fcb3e3f7 url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.3.0" logging: dependency: transitive description: @@ -1359,4 +1375,4 @@ packages: version: "3.1.1" sdks: dart: ">=2.19.0 <3.0.0" - flutter: ">=3.7.6" + flutter: ">=3.7.8" diff --git a/pubspec.yaml b/pubspec.yaml index 4332f69..5b9915e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,21 +1,22 @@ name: hacki description: A Hacker News reader. -version: 1.3.3+102 +version: 1.3.4+103 publish_to: none environment: sdk: ">=2.17.0 <3.0.0" - flutter: "3.7.6" + flutter: "3.7.8" dependencies: - adaptive_theme: ^3.0.0 + adaptive_theme: ^3.2.0 badges: ^3.0.2 bloc: ^8.1.1 cached_network_image: ^3.2.3 clipboard: ^0.1.3 collection: ^1.17.0 connectivity_plus: ^3.0.2 - dio: ^4.0.6 + device_info_plus: ^8.1.0 + dio: ^5.0.3 equatable: ^2.0.5 fast_gbk: ^1.0.0 feature_discovery: @@ -44,7 +45,7 @@ dependencies: hydrated_bloc: ^9.1.0 intl: ^0.18.0 linkify: ^4.1.0 - logger: ^1.1.0 + logger: ^1.3.0 memoize: ^3.0.0 package_info_plus: ^3.0.3 path: ^1.8.2 diff --git a/submodules/flutter b/submodules/flutter index 12cb4eb..90c64ed 160000 --- a/submodules/flutter +++ b/submodules/flutter @@ -1 +1 @@ -Subproject commit 12cb4eb7a009f52b347b62ade7cb4854b926af72 +Subproject commit 90c64ed42ba53a52d18f0cb3b17666c8662ed2a0