From f72f6fc0f6eea3a400ed1f896247c6644ba0f5b0 Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Wed, 19 Jan 2022 16:50:03 -0500 Subject: [PATCH] Add dismiss emote menu when tapping video --- lib/screens/channel/chat/chat.dart | 89 +++++++++++++--------------- lib/screens/channel/video/video.dart | 41 +++++-------- lib/screens/channel/video_chat.dart | 48 +++++++++++---- 3 files changed, 95 insertions(+), 83 deletions(-) diff --git a/lib/screens/channel/chat/chat.dart b/lib/screens/channel/chat/chat.dart index c5f2ef43..53d4f5f0 100644 --- a/lib/screens/channel/chat/chat.dart +++ b/lib/screens/channel/chat/chat.dart @@ -20,57 +20,50 @@ class Chat extends StatelessWidget { child: Stack( alignment: AlignmentDirectional.bottomCenter, children: [ - GestureDetector( - onTap: () { - // If tapping chat, hide the keyboard and emote menu. - FocusManager.instance.primaryFocus?.unfocus(); - if (chatStore.assetsStore.showEmoteMenu) chatStore.assetsStore.showEmoteMenu = false; - }, - child: MediaQuery( - data: MediaQuery.of(context).copyWith(textScaleFactor: chatStore.settings.messageScale), - child: DefaultTextStyle( - style: DefaultTextStyle.of(context).style.copyWith(fontSize: chatStore.settings.fontSize), - child: Observer( - builder: (context) => ListView.separated( - padding: const EdgeInsets.symmetric(vertical: 5.0), - addAutomaticKeepAlives: false, - addRepaintBoundaries: false, - itemCount: chatStore.messages.length, - controller: chatStore.scrollController, - separatorBuilder: (context, index) => SizedBox(height: chatStore.settings.messageSpacing), - itemBuilder: (context, index) => Observer( - builder: (context) { - final message = chatStore.messages[index]; + MediaQuery( + data: MediaQuery.of(context).copyWith(textScaleFactor: chatStore.settings.messageScale), + child: DefaultTextStyle( + style: DefaultTextStyle.of(context).style.copyWith(fontSize: chatStore.settings.fontSize), + child: Observer( + builder: (context) => ListView.separated( + padding: const EdgeInsets.symmetric(vertical: 5.0), + addAutomaticKeepAlives: false, + addRepaintBoundaries: false, + itemCount: chatStore.messages.length, + controller: chatStore.scrollController, + separatorBuilder: (context, index) => SizedBox(height: chatStore.settings.messageSpacing), + itemBuilder: (context, index) => Observer( + builder: (context) { + final message = chatStore.messages[index]; - if (message.user != null && message.user != chatStore.auth.user.details?.login) { - return InkWell( - onTap: () { - FocusManager.instance.primaryFocus?.unfocus(); - if (chatStore.assetsStore.showEmoteMenu) chatStore.assetsStore.showEmoteMenu = false; - }, - onLongPress: () => showModalBottomSheet( - context: context, - builder: (context) => ChatUserModal( - username: message.user!, - chatStore: chatStore, - userId: message.tags['user-id']!, - displayName: message.tags['display-name']!, - ), + if (message.user != null && message.user != chatStore.auth.user.details?.login) { + return InkWell( + onTap: () { + FocusManager.instance.primaryFocus?.unfocus(); + if (chatStore.assetsStore.showEmoteMenu) chatStore.assetsStore.showEmoteMenu = false; + }, + onLongPress: () => showModalBottomSheet( + context: context, + builder: (context) => ChatUserModal( + username: message.user!, + chatStore: chatStore, + userId: message.tags['user-id']!, + displayName: message.tags['display-name']!, ), - child: ChatMessage( - ircMessage: message, - assetsStore: chatStore.assetsStore, - settingsStore: chatStore.settings, - ), - ); - } - return ChatMessage( - ircMessage: message, - assetsStore: chatStore.assetsStore, - settingsStore: chatStore.settings, + ), + child: ChatMessage( + ircMessage: message, + assetsStore: chatStore.assetsStore, + settingsStore: chatStore.settings, + ), ); - }, - ), + } + return ChatMessage( + ircMessage: message, + assetsStore: chatStore.assetsStore, + settingsStore: chatStore.settings, + ); + }, ), ), ), diff --git a/lib/screens/channel/video/video.dart b/lib/screens/channel/video/video.dart index 9f32090d..13dfc5c3 100644 --- a/lib/screens/channel/video/video.dart +++ b/lib/screens/channel/video/video.dart @@ -58,34 +58,25 @@ class Video extends StatelessWidget { ), }, ), - GestureDetector( - onTap: () { - if (textFieldFocus.hasFocus) { - textFieldFocus.unfocus(); - } else { - videoStore.handleVideoTap(); - } - }, - child: Observer( - builder: (_) { - if (videoStore.paused) return VideoOverlay(videoStore: videoStore); - return SizedBox.expand( - child: Observer( - builder: (_) => AnimatedOpacity( - opacity: videoStore.overlayVisible ? 1.0 : 0.0, - duration: const Duration(milliseconds: 200), - child: ColoredBox( - color: const Color.fromRGBO(0, 0, 0, 0.5), - child: IgnorePointer( - ignoring: !videoStore.overlayVisible, - child: VideoOverlay(videoStore: videoStore), - ), + Observer( + builder: (_) { + if (videoStore.paused) return VideoOverlay(videoStore: videoStore); + return SizedBox.expand( + child: Observer( + builder: (_) => AnimatedOpacity( + opacity: videoStore.overlayVisible ? 1.0 : 0.0, + duration: const Duration(milliseconds: 200), + child: ColoredBox( + color: const Color.fromRGBO(0, 0, 0, 0.5), + child: IgnorePointer( + ignoring: !videoStore.overlayVisible, + child: VideoOverlay(videoStore: videoStore), ), ), ), - ); - }, - ), + ), + ); + }, ) ], ); diff --git a/lib/screens/channel/video_chat.dart b/lib/screens/channel/video_chat.dart index f2ee64b1..34f11a09 100644 --- a/lib/screens/channel/video_chat.dart +++ b/lib/screens/channel/video_chat.dart @@ -25,21 +25,49 @@ class _VideoChatState extends State { final chatStore = widget.chatStore; final settingsStore = chatStore.settings; - final video = Video( - key: GlobalKey(), + final videoStore = VideoStore( + twitchApi: context.read(), userLogin: chatStore.channelName, - textFieldFocus: chatStore.textFieldFocusNode, - videoStore: VideoStore( - twitchApi: context.read(), + authStore: chatStore.auth, + settingsStore: chatStore.settings, + ); + + final video = GestureDetector( + onTap: () { + if (chatStore.assetsStore.showEmoteMenu) { + chatStore.assetsStore.showEmoteMenu = false; + } else { + if (chatStore.textFieldFocusNode.hasFocus) { + chatStore.textFieldFocusNode.unfocus(); + } else { + videoStore.handleVideoTap(); + } + } + }, + child: Video( + key: GlobalKey(), userLogin: chatStore.channelName, - authStore: chatStore.auth, - settingsStore: chatStore.settings, + textFieldFocus: chatStore.textFieldFocusNode, + videoStore: videoStore, ), ); - final chat = Chat( - key: GlobalKey(), - chatStore: chatStore, + final chat = GestureDetector( + onTap: () { + if (chatStore.assetsStore.showEmoteMenu) { + chatStore.assetsStore.showEmoteMenu = false; + } else { + if (chatStore.textFieldFocusNode.hasFocus) { + chatStore.textFieldFocusNode.unfocus(); + } else { + videoStore.handleVideoTap(); + } + } + }, + child: Chat( + key: GlobalKey(), + chatStore: chatStore, + ), ); final appBar = AppBar(