Skip to content

Commit

Permalink
Merge pull request #938 from S-ecki/develop
Browse files Browse the repository at this point in the history
feat(ui): Add Channel Header customization
  • Loading branch information
imtoori authored Apr 27, 2022
2 parents 5d0177d + 622efa7 commit d58f727
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/stream_chat_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Upcoming

✅ Added

- `centerTitle` and `elevation` properties to `ChannelHeader`, `ThreadHeader` and `ChannelListHeader`.

🐞 Fixed

- [[#1067]](https://github.com/GetStream/stream-chat-flutter/issues/1067): Fix name text overflow in reaction card.
Expand Down
21 changes: 18 additions & 3 deletions packages/stream_chat_flutter/lib/src/channel_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
this.showConnectionStateTile = false,
this.title,
this.subtitle,
this.centerTitle,
this.leading,
this.actions,
this.backgroundColor,
this.elevation = 1,
}) : preferredSize = const Size.fromHeight(kToolbarHeight),
super(key: key);

Expand Down Expand Up @@ -92,6 +94,9 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
/// Subtitle widget
final Widget? subtitle;

/// Whether the title should be centered
final bool? centerTitle;

/// Leading widget
final Widget? leading;

Expand All @@ -102,8 +107,16 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
/// The background color for this [ChannelHeader].
final Color? backgroundColor;

/// The elevation for this [ChannelHeader].
final double elevation;

@override
Widget build(BuildContext context) {
final effectiveCenterTitle = getEffectiveCenterTitle(
Theme.of(context),
actions: actions,
centerTitle: centerTitle,
);
final channel = StreamChannel.of(context).channel;
final channelHeaderTheme = ChannelHeaderTheme.of(context);

Expand Down Expand Up @@ -144,7 +157,7 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
systemOverlayStyle: theme.brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark,
elevation: 1,
elevation: elevation,
leading: leadingWidget,
backgroundColor: backgroundColor ?? channelHeaderTheme.color,
actions: actions ??
Expand All @@ -162,14 +175,16 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
),
),
],
centerTitle: true,
centerTitle: centerTitle,
title: InkWell(
onTap: onTitleTap,
child: SizedBox(
height: preferredSize.height,
width: preferredSize.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: effectiveCenterTitle
? CrossAxisAlignment.center
: CrossAxisAlignment.stretch,
children: <Widget>[
title ??
ChannelName(
Expand Down
12 changes: 10 additions & 2 deletions packages/stream_chat_flutter/lib/src/channel_list_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
this.showConnectionStateTile = false,
this.preNavigationCallback,
this.subtitle,
this.centerTitle,
this.leading,
this.actions,
this.backgroundColor,
this.elevation = 1,
}) : super(key: key);

/// Pass this if you don't have a [StreamChatClient] in your widget tree.
Expand All @@ -83,6 +85,9 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
/// Subtitle widget
final Widget? subtitle;

/// Whether the title should be centered
final bool? centerTitle;

/// Leading widget
/// By default it shows the logged in user avatar
final Widget? leading;
Expand All @@ -94,6 +99,9 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
/// The background color for this [ChannelListHeader].
final Color? backgroundColor;

/// The elevation for this [ChannelListHeader].
final double elevation;

@override
Widget build(BuildContext context) {
final _client = client ?? StreamChat.of(context).client;
Expand Down Expand Up @@ -128,10 +136,10 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget {
systemOverlayStyle: theme.brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark,
elevation: 1,
elevation: elevation,
backgroundColor:
backgroundColor ?? channelListHeaderThemeData.color,
centerTitle: true,
centerTitle: centerTitle,
leading: leading ??
Center(
child: user != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ class _MessageListViewState extends State<MessageListView> {
return ((index + 2) * 2) - 1;
}
}
return null;
},

// Item Count -> 8 (1 parent, 2 header+footer, 2 top+bottom, 3 messages)
Expand Down
21 changes: 19 additions & 2 deletions packages/stream_chat_flutter/lib/src/thread_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
this.onBackPressed,
this.title,
this.subtitle,
this.centerTitle,
this.leading,
this.actions,
this.onTitleTap,
this.showTypingIndicator = true,
this.backgroundColor,
this.elevation = 1,
}) : preferredSize = const Size.fromHeight(kToolbarHeight),
super(key: key);

Expand All @@ -92,6 +94,9 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
/// Subtitle widget
final Widget? subtitle;

/// Whether the title should be centered
final bool? centerTitle;

/// Leading widget
final Widget? leading;

Expand All @@ -105,8 +110,17 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
/// The background color of this [ThreadHeader].
final Color? backgroundColor;

/// The elevation for this [ThreadHeader].
final double elevation;

@override
Widget build(BuildContext context) {
final effectiveCenterTitle = getEffectiveCenterTitle(
Theme.of(context),
actions: actions,
centerTitle: centerTitle,
);

final channelHeaderTheme = ChannelHeaderTheme.of(context);

final defaultSubtitle = subtitle ??
Expand Down Expand Up @@ -134,7 +148,7 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
systemOverlayStyle: theme.brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark,
elevation: 1,
elevation: elevation,
leading: leading ??
(showBackButton
? StreamBackButton(
Expand All @@ -144,7 +158,7 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
)
: const SizedBox()),
backgroundColor: backgroundColor ?? channelHeaderTheme.color,
centerTitle: true,
centerTitle: centerTitle,
actions: actions,
title: InkWell(
onTap: onTitleTap,
Expand All @@ -153,6 +167,9 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
width: 250,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: effectiveCenterTitle
? CrossAxisAlignment.center
: CrossAxisAlignment.stretch,
children: [
title ??
Text(
Expand Down
6 changes: 6 additions & 0 deletions packages/stream_chat_flutter/lib/src/typing_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class TypingIndicator extends StatelessWidget {
.where((element) => element.value.parentId == parentId)
.map((e) => e.key)),
builder: (context, data) => AnimatedSwitcher(
layoutBuilder: (currentChild, previousChildren) => Stack(
children: <Widget>[
...previousChildren,
if (currentChild != null) currentChild,
],
),
duration: const Duration(milliseconds: 300),
child: data.isNotEmpty
? Padding(
Expand Down
22 changes: 22 additions & 0 deletions packages/stream_chat_flutter/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ Future<void> launchURL(BuildContext context, String url) async {
}
}

/// Get centerTitle considering a default and platform specific behaviour
bool getEffectiveCenterTitle(
ThemeData theme, {
bool? centerTitle,
List<Widget>? actions,
}) {
if (centerTitle != null) return centerTitle;
if (theme.appBarTheme.centerTitle != null) {
return theme.appBarTheme.centerTitle!;
}
switch (theme.platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
return false;
case TargetPlatform.iOS:
case TargetPlatform.macOS:
return actions == null || actions.length < 2;
}
}

/// Shows confirmation dialog
Future<bool?> showConfirmationDialog(
BuildContext context, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ GlobalStreamChatLocalizations? getStreamChatTranslation(Locale locale) {
return const StreamChatLocalizationsKo();
case 'pt':
return const StreamChatLocalizationsPt();
default:
return null;
}
}

Expand Down

0 comments on commit d58f727

Please sign in to comment.