Skip to content

Commit

Permalink
fix: defocus input on tap and drawer open (#409)
Browse files Browse the repository at this point in the history
* fix: defocus input on tap and drawer open

* fix: defocus input when long pressing messages
  • Loading branch information
cswills committed May 26, 2022
1 parent 9cd9fc6 commit 55e50bb
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 163 deletions.
2 changes: 2 additions & 0 deletions lib/components/chat_history/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class ChatHistoryMessage extends StatelessWidget {

return Material(
child: InkWell(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
onLongPress: () async {
FocusManager.instance.primaryFocus?.unfocus();
var showTimeoutDialog = await showDialog<bool>(
context: context,
builder: (context) {
Expand Down
339 changes: 176 additions & 163 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,173 +165,186 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
Widget build(BuildContext context) {
final orientation = MediaQuery.of(context).orientation;

return Scaffold(
key: _scaffoldKey,
drawer: Sidebar(channel: widget.channel),
endDrawer: LeftDrawerWidget(channel: widget.channel),
appBar: HeaderBarWidget(
onChannelSelect: widget.onChannelSelect,
channel: widget.channel,
actions: [
Consumer2<ActivityFeedModel, LayoutModel>(
builder: (context, activityFeedModel, layoutModel, child) {
if (!activityFeedModel.isEnabled) {
return Container();
}
return IconButton(
icon: Icon(layoutModel.isShowNotifications
? Icons.notifications
: Icons.notifications_outlined),
tooltip: 'Activity feed',
onPressed: () {
layoutModel.isShowNotifications =
!layoutModel.isShowNotifications;
},
);
}),
Consumer<LayoutModel>(builder: (context, layoutModel, child) {
return IconButton(
icon: Icon(layoutModel.isShowPreview
? Icons.preview
: Icons.preview_outlined),
tooltip: 'Stream preview',
onPressed: () {
layoutModel.isShowPreview = !layoutModel.isShowPreview;
},
);
}),
Consumer<TtsModel>(builder: (context, ttsModel, child) {
return IconButton(
icon: Icon(ttsModel.enabled
? Icons.record_voice_over
: Icons.voice_over_off),
tooltip: 'Text to speech',
onPressed: () {
ttsModel.enabled = !ttsModel.enabled;
});
}),
IconButton(
icon: const Icon(Icons.people),
tooltip: 'Current viewers',
onPressed: () {
_scaffoldKey.currentState?.openEndDrawer();
},
),
]),
body: Container(
color: Theme.of(context).primaryColor,
child: SafeArea(
child: Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: Builder(builder: (context) {
final chatPanelFooter = Consumer<LayoutModel>(
builder: (context, layoutModel, child) {
if (layoutModel.isInteractionLockable && layoutModel.locked) {
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Scaffold(
key: _scaffoldKey,
drawer: Sidebar(channel: widget.channel),
endDrawer: LeftDrawerWidget(channel: widget.channel),
onDrawerChanged: (isOpened) =>
FocusManager.instance.primaryFocus?.unfocus(),
onEndDrawerChanged: (isOpened) =>
FocusManager.instance.primaryFocus?.unfocus(),
appBar: HeaderBarWidget(
onChannelSelect: widget.onChannelSelect,
channel: widget.channel,
actions: [
Consumer2<ActivityFeedModel, LayoutModel>(
builder: (context, activityFeedModel, layoutModel, child) {
if (!activityFeedModel.isEnabled) {
return Container();
}
return child!;
},
child: Consumer<UserModel>(
builder: (context, userModel, child) {
if (!userModel.isSignedIn()) {
return Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Flexible(child: Divider()),
Padding(
padding: const EdgeInsets.all(8),
child: Text("Sign in to send messages",
style: Theme.of(context)
.textTheme
.labelLarge)),
const Flexible(child: Divider()),
]),
const SignInWithTwitch(),
]);
}

return child!;
return IconButton(
icon: Icon(layoutModel.isShowNotifications
? Icons.notifications
: Icons.notifications_outlined),
tooltip: 'Activity feed',
onPressed: () {
layoutModel.isShowNotifications =
!layoutModel.isShowNotifications;
},
);
}),
Consumer<LayoutModel>(builder: (context, layoutModel, child) {
return IconButton(
icon: Icon(layoutModel.isShowPreview
? Icons.preview
: Icons.preview_outlined),
tooltip: 'Stream preview',
onPressed: () {
layoutModel.isShowPreview = !layoutModel.isShowPreview;
},
);
}),
Consumer<TtsModel>(builder: (context, ttsModel, child) {
return IconButton(
icon: Icon(ttsModel.enabled
? Icons.record_voice_over
: Icons.voice_over_off),
tooltip: 'Text to speech',
onPressed: () {
ttsModel.enabled = !ttsModel.enabled;
});
}),
IconButton(
icon: const Icon(Icons.people),
tooltip: 'Current viewers',
onPressed: () {
_scaffoldKey.currentState?.openEndDrawer();
},
child: MessageInputWidget(
channel: widget.channel,
),
),
);
if (orientation == Orientation.portrait) {
return Column(children: [
Consumer<LayoutModel>(builder: (context, layoutModel, child) {
if (layoutModel.isShowNotifications) {
return ResizableWidget(
resizable: !layoutModel.locked,
height: layoutModel.panelHeight,
width: layoutModel.panelWidth,
onResizeHeight: (height) {
layoutModel.panelHeight = height;
},
onResizeWidth: (width) {
layoutModel.panelWidth = width;
},
child: const ActivityFeedPanelWidget());
} else if (layoutModel.isShowPreview) {
return SizedBox(
height: MediaQuery.of(context).size.width * 9 / 16,
child: StreamPreview(
channelDisplayName: widget.channel.displayName));
} else {
return Container();
}
}),
Expanded(
child: DiscoWidget(
isEnabled: widget.isDiscoModeEnabled,
child: ChatPanelWidget(channel: widget.channel))),
chatPanelFooter,
]);
} else {
// landscape
return Row(children: [
Consumer<LayoutModel>(builder: (context, layoutModel, child) {
if (!layoutModel.isShowNotifications &&
!layoutModel.isShowPreview) {
return Container();
}
return ResizableWidget(
resizable: !layoutModel.locked,
height: layoutModel.panelHeight,
width: layoutModel.panelWidth,
onResizeHeight: (height) {
layoutModel.panelHeight = height;
},
onResizeWidth: (width) {
layoutModel.panelWidth = width;
},
child: Consumer<LayoutModel>(
builder: (context, layoutModel, child) {
if (layoutModel.isShowNotifications) {
return const ActivityFeedPanelWidget();
} else if (layoutModel.isShowPreview) {
return StreamPreview(
channelDisplayName: widget.channel.displayName);
} else {
return Container();
}
}));
}),
Expanded(
child: Column(children: [
Expanded(
child: DiscoWidget(
isEnabled: widget.isDiscoModeEnabled,
child: ChatPanelWidget(channel: widget.channel))),
chatPanelFooter,
]))
]);
}
}),
]),
body: Container(
color: Theme.of(context).primaryColor,
child: SafeArea(
child: Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: Builder(builder: (context) {
final chatPanelFooter = Consumer<LayoutModel>(
builder: (context, layoutModel, child) {
if (layoutModel.isInteractionLockable &&
layoutModel.locked) {
return Container();
}
return child!;
},
child: Consumer<UserModel>(
builder: (context, userModel, child) {
if (!userModel.isSignedIn()) {
return Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Flexible(child: Divider()),
Padding(
padding: const EdgeInsets.all(8),
child: Text("Sign in to send messages",
style: Theme.of(context)
.textTheme
.labelLarge)),
const Flexible(child: Divider()),
]),
const SignInWithTwitch(),
]);
}

return child!;
},
child: MessageInputWidget(
channel: widget.channel,
),
),
);
if (orientation == Orientation.portrait) {
return Column(children: [
Consumer<LayoutModel>(
builder: (context, layoutModel, child) {
if (layoutModel.isShowNotifications) {
return ResizableWidget(
resizable: !layoutModel.locked,
height: layoutModel.panelHeight,
width: layoutModel.panelWidth,
onResizeHeight: (height) {
layoutModel.panelHeight = height;
},
onResizeWidth: (width) {
layoutModel.panelWidth = width;
},
child: const ActivityFeedPanelWidget());
} else if (layoutModel.isShowPreview) {
return SizedBox(
height:
MediaQuery.of(context).size.width * 9 / 16,
child: StreamPreview(
channelDisplayName:
widget.channel.displayName));
} else {
return Container();
}
}),
Expanded(
child: DiscoWidget(
isEnabled: widget.isDiscoModeEnabled,
child: ChatPanelWidget(channel: widget.channel))),
chatPanelFooter,
]);
} else {
// landscape
return Row(children: [
Consumer<LayoutModel>(
builder: (context, layoutModel, child) {
if (!layoutModel.isShowNotifications &&
!layoutModel.isShowPreview) {
return Container();
}
return ResizableWidget(
resizable: !layoutModel.locked,
height: layoutModel.panelHeight,
width: layoutModel.panelWidth,
onResizeHeight: (height) {
layoutModel.panelHeight = height;
},
onResizeWidth: (width) {
layoutModel.panelWidth = width;
},
child: Consumer<LayoutModel>(
builder: (context, layoutModel, child) {
if (layoutModel.isShowNotifications) {
return const ActivityFeedPanelWidget();
} else if (layoutModel.isShowPreview) {
return StreamPreview(
channelDisplayName:
widget.channel.displayName);
} else {
return Container();
}
}));
}),
Expanded(
child: Column(children: [
Expanded(
child: DiscoWidget(
isEnabled: widget.isDiscoModeEnabled,
child:
ChatPanelWidget(channel: widget.channel))),
chatPanelFooter,
]))
]);
}
}),
),
),
),
),
),
);
));
}
}

0 comments on commit 55e50bb

Please sign in to comment.