mattermost-mobile/app/components/navigation_header/header.tsx
Daniel Espino García bb7ff622af
Add Playbooks read-only support for mobile devices (#8978)
* Add the channel options to get into playbooks (#8750)

* Add the channel options to get into playbooks

* Use playbook run id instead of playbook id

* i18n

* Fix issues and move playbooks to the products folder

* Address some tests

* Fix test

* Address design issues

* Add requested comment

---------

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* Playbooks database (#8802)

* Add lastPlaybookFetchAt to channel table (#8916)

* Add lastPlaybookFetchAt to channel table

* Add missing commit

* Use my_channel table instead

* Fix test

* Address feedback

* First implementation of playbooks API (#8897)

* First implementation of playbooks API

* Add version check

* Address feedback

* Fix test

* Add last fetch at usage and other improvements

* Simplify test

* Add sort_order, update_at and previousReminder columns (#8927)

* Add sort_order, update_at and previousReminder columns

* Remove order from the schema

* Fix tests

* Add tests

* Add websockets for playbooks (#8947)

* Add websocket events for playbooks

* Fix typo

* Add playbook run list (#8761)

* Add the channel options to get into playbooks

* Use playbook run id instead of playbook id

* i18n

* Fix issues and move playbooks to the products folder

* Address some tests

* Fix test

* Add playbook run list

* Add missing texts

* Add back button support and item size to flash list

* Address design issues

* Add requested comment

* Standardize tag and use it in the card

* Fix merge

* Add API related functionality

---------

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* Add playbooks run details (#8872)

* Add the channel options to get into playbooks

* Use playbook run id instead of playbook id

* i18n

* Fix issues and move playbooks to the products folder

* Address some tests

* Fix test

* Add playbook run list

* Add missing texts

* Add back button support and item size to flash list

* Address design issues

* Add requested comment

* Standardize tag and use it in the card

* Add playbooks run details

* Fix merge

* Add API related functionality

* Add API related changes

* Order fixes

* Several fixes

* Add error state on playbook run

* i18n-extract

* Fix tests

* Fix test

* Several fixes

* Fixes and add missing UI elements

* i18n-extract

* Fix tests

* Remove files from bad merge

---------

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* Add missing tests for playbooks (#8976)

* Add the channel options to get into playbooks

* Use playbook run id instead of playbook id

* i18n

* Fix issues and move playbooks to the products folder

* Address some tests

* Fix test

* Add playbook run list

* Add missing texts

* Add back button support and item size to flash list

* Address design issues

* Add requested comment

* Standardize tag and use it in the card

* Add playbooks run details

* Fix merge

* Add API related functionality

* Add API related changes

* Order fixes

* Several fixes

* Add error state on playbook run

* i18n-extract

* Fix tests

* Fix test

* Several fixes

* Fixes and add missing UI elements

* i18n-extract

* Fix tests

* Remove files from bad merge

* Add tests

* Fix typo

* Add missing strings

* Fix tests and skip some

* Fix test

* Fix typo

---------

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* Address feedback

* Address feedback and fix tests

* Address comments and fix tests

* Address feedback

* Address plugin changes and fix bugs

---------

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2025-07-14 09:21:37 +02:00

272 lines
8.8 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useMemo} from 'react';
import {Platform, Text, View} from 'react-native';
import Animated, {useAnimatedStyle, withTiming} from 'react-native-reanimated';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import CompassIcon from '@components/compass_icon';
import TouchableWithFeedback from '@components/touchable_with_feedback';
import ViewConstants from '@constants/view';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
import {typography} from '@utils/typography';
export type HeaderRightButton = {
borderless?: boolean;
buttonType?: 'native' | 'opacity' | 'highlight';
color?: string;
iconName: string;
count?: number;
onPress: () => void;
rippleRadius?: number;
testID?: string;
}
type Props = {
defaultHeight: number;
hasSearch: boolean;
isLargeTitle: boolean;
heightOffset: number;
leftComponent?: React.ReactElement;
onBackPress?: () => void;
onTitlePress?: () => void;
rightButtons?: HeaderRightButton[];
scrollValue?: Animated.SharedValue<number>;
showBackButton?: boolean;
subtitle?: string;
subtitleCompanion?: React.ReactElement;
theme: Theme;
title?: string;
}
const hitSlop = {top: 20, bottom: 20, left: 20, right: 20};
const rightButtonHitSlop = {top: 20, bottom: 5, left: 5, right: 5};
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
centered: {
alignItems: Platform.select({android: 'flex-start', ios: 'center'}),
},
container: {
alignItems: 'center',
backgroundColor: theme.sidebarBg,
flexDirection: 'row',
justifyContent: 'flex-start',
paddingHorizontal: 16,
zIndex: 10,
},
subtitleContainer: {
flexDirection: 'row',
justifyContent: Platform.select({android: 'flex-start', ios: 'center'}),
left: Platform.select({ios: undefined, default: 3}),
},
subtitle: {
color: changeOpacity(theme.sidebarHeaderTextColor, 0.72),
...typography('Body', 75),
lineHeight: 12,
marginBottom: 8,
marginTop: 2,
height: 13,
},
titleContainer: {
alignItems: Platform.select({android: 'flex-start', ios: 'center'}),
justifyContent: 'center',
flex: 3,
height: '100%',
paddingHorizontal: 8,
...Platform.select({
ios: {
paddingHorizontal: 60,
flex: undefined,
width: '100%',
position: 'absolute',
left: 16,
bottom: 0,
zIndex: 1,
},
}),
},
leftAction: {
alignItems: 'center',
flexDirection: 'row',
},
leftContainer: {
height: '100%',
justifyContent: 'center',
...Platform.select({
ios: {
paddingLeft: 16,
zIndex: 5,
position: 'absolute',
bottom: 0,
},
}),
},
rightContainer: {
alignItems: 'center',
flexDirection: 'row',
height: '100%',
justifyContent: 'flex-end',
...Platform.select({
ios: {
right: 16,
bottom: 0,
position: 'absolute',
zIndex: 2,
},
}),
},
rightButtonContainer: {
flexDirection: 'row',
alignItems: 'center',
gap: 6,
},
rightIcon: {
padding: 5,
},
title: {
color: theme.sidebarHeaderTextColor,
...typography('Heading', 300),
},
}));
const Header = ({
defaultHeight,
hasSearch,
isLargeTitle,
heightOffset,
leftComponent,
onBackPress,
onTitlePress,
rightButtons,
scrollValue,
showBackButton = true,
subtitle,
subtitleCompanion,
theme,
title,
}: Props) => {
const styles = getStyleSheet(theme);
const insets = useSafeAreaInsets();
const opacity = useAnimatedStyle(() => {
if (!isLargeTitle) {
return {opacity: 1};
}
if (hasSearch) {
return {opacity: 0};
}
const barHeight = heightOffset - ViewConstants.LARGE_HEADER_TITLE_HEIGHT;
const val = (scrollValue?.value || 0);
const showDuration = 200;
const hideDuration = 50;
const duration = val >= barHeight ? showDuration : hideDuration;
const opacityValue = val >= barHeight ? 1 : 0;
return {
opacity: withTiming(opacityValue, {duration}),
};
}, [heightOffset, isLargeTitle, hasSearch]);
const containerAnimatedStyle = useAnimatedStyle(() => ({
height: defaultHeight,
paddingTop: insets.top,
}), [defaultHeight]);
const containerStyle = useMemo(() => (
[styles.container, containerAnimatedStyle]), [styles, containerAnimatedStyle]);
const additionalTitleStyle = useMemo(() => ({
marginLeft: Platform.select({android: showBackButton && !leftComponent ? 20 : 0}),
}), [leftComponent, showBackButton]);
return (
<Animated.View style={containerStyle}>
{showBackButton &&
<Animated.View style={styles.leftContainer}>
<TouchableWithFeedback
borderlessRipple={true}
onPress={onBackPress}
rippleRadius={20}
type={Platform.select({android: 'native', default: 'opacity'})}
testID='navigation.header.back'
hitSlop={hitSlop}
>
<Animated.View style={styles.leftAction}>
<CompassIcon
size={24}
name={Platform.select({android: 'arrow-left', ios: 'arrow-back-ios'})!}
color={theme.sidebarHeaderTextColor}
/>
{leftComponent}
</Animated.View>
</TouchableWithFeedback>
</Animated.View>
}
<Animated.View style={[styles.titleContainer, additionalTitleStyle]}>
<TouchableWithFeedback
disabled={!onTitlePress}
onPress={onTitlePress}
type='opacity'
>
<View style={styles.centered}>
{!hasSearch &&
<Animated.Text
ellipsizeMode='tail'
numberOfLines={1}
style={[styles.title, opacity]}
testID='navigation.header.title'
>
{title}
</Animated.Text>
}
{!isLargeTitle && Boolean(subtitle || subtitleCompanion) &&
<View style={styles.subtitleContainer}>
<Text
ellipsizeMode='tail'
numberOfLines={1}
style={styles.subtitle}
testID='navigation.header.subtitle'
>
{subtitle}
</Text>
{subtitleCompanion}
</View>
}
</View>
</TouchableWithFeedback>
</Animated.View>
<Animated.View style={styles.rightContainer}>
{Boolean(rightButtons?.length) &&
rightButtons?.map((r) => (
<TouchableWithFeedback
key={r.iconName}
borderlessRipple={r.borderless === undefined ? true : r.borderless}
hitSlop={rightButtonHitSlop}
onPress={r.onPress}
rippleRadius={r.rippleRadius || 20}
type={r.buttonType || Platform.select({android: 'native', default: 'opacity'})}
style={styles.rightIcon}
testID={r.testID}
>
<View style={styles.rightButtonContainer}>
<CompassIcon
size={24}
name={r.iconName}
color={r.color || theme.sidebarHeaderTextColor}
/>
{Boolean(r.count) && (
<Text style={styles.title}>{r.count}</Text>
)}
</View>
</TouchableWithFeedback>
))
}
</Animated.View>
</Animated.View>
);
};
export default React.memo(Header);