mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-05 18:38:54 +00:00
* Expo-Router partial migration * Full migration to ExpoRouter * i18n * add tests * Merge branch 'main' into expo-router * align package-lock.json * i18n * feedback review * feedback review * android 16kb patch * Refactored emoji picker keyboard using a state machine * set android launch_screen in drawables instead of layout * no conditional hooks * remove duplicate call in test * address feedback * fix tests and address more feedback * small corrections * small corrections * small corrections * fix draft test * fix draft test 2 * remove navigateToScreen in draff test * fix nit in draft test * remove doc file * Feedback review * fix snapshots * improve test coverage * fix i18n * Upgrade t o RN 0.83, other dependencies and new architecture (#9737) * library hardware-keyboard android new arch support fix * library rnshare android new arch support fix * library rnutils android new arch support fix * library secure-pdf-viewer add new arch support * Enable new arch on iOS and Android * update emm and network client with new-arch * update intune to use new-arch * performance improvements * fix tests * fixes post input on new-arch * fix android emoji picker * remove doc * run tests in parallel * upgrade to React Native 0.83.9, Expo 55, React 19, and New Architecture Bumps core dependencies to their latest versions: - React Native 0.77.3 → 0.83.9 (New Architecture enabled) - React 18.3.1 → 19.2.5 - Expo SDK 52 → 55 - TypeScript 5.8.3 → 6.0.3 - Node.js 22.16.0 → 24.15.0 - react-native-reanimated 3.17.3 → 4.3.0 - Various other dependency upgrades Migrates iOS AppDelegate from Objective-C to Swift, updates Android build tooling and Gradle wrapper, refreshes all patches and font assets, and adapts app code, tests, and CI workflows throughout for API changes introduced by these upgrades. * remove unecessary dismissKeyboard in notifications * feedback review * update intune to use new-arch * update @mattermost deps * missing i18n string * additional fixes * update fastlane
187 lines
5.3 KiB
TypeScript
187 lines
5.3 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, TouchableOpacity, View} from 'react-native';
|
|
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated';
|
|
|
|
import CompassIcon from '@components/compass_icon';
|
|
import {useTheme} from '@context/theme';
|
|
import {useWindowDimensions} from '@hooks/device';
|
|
import {nonBreakingString} from '@utils/strings';
|
|
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
|
|
import {typography} from '@utils/typography';
|
|
|
|
import {CHIP_HEIGHT} from './constants';
|
|
|
|
type SelectedChipProps = {
|
|
onPress?: () => void;
|
|
testID?: string;
|
|
action?: {
|
|
icon: 'remove' | 'downArrow';
|
|
onPress?: () => void;
|
|
};
|
|
showAnimation?: boolean;
|
|
label: string;
|
|
prefix?: React.ReactNode;
|
|
maxWidth?: number;
|
|
type?: 'normal' | 'link' | 'danger';
|
|
boldText?: boolean;
|
|
}
|
|
|
|
const FADE_DURATION = 100;
|
|
|
|
const getStyleFromTheme = makeStyleSheetFromTheme((theme) => {
|
|
return {
|
|
container: {
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
flexDirection: 'row',
|
|
borderRadius: 16,
|
|
height: CHIP_HEIGHT,
|
|
backgroundColor: changeOpacity(theme.centerChannelColor, 0.08),
|
|
padding: 2,
|
|
},
|
|
dangerContainer: {
|
|
backgroundColor: changeOpacity(theme.dndIndicator, 0.08),
|
|
},
|
|
text: {
|
|
color: theme.centerChannelColor,
|
|
...typography('Body', 100),
|
|
},
|
|
linkText: {
|
|
color: theme.linkColor,
|
|
},
|
|
dangerText: {
|
|
color: theme.dndIndicator,
|
|
},
|
|
remove: {
|
|
justifyContent: 'center',
|
|
marginLeft: 5,
|
|
marginRight: 4,
|
|
},
|
|
chipContent: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
},
|
|
boldText: {
|
|
...typography('Body', 100, 'SemiBold'),
|
|
},
|
|
};
|
|
});
|
|
|
|
export default function BaseChip({
|
|
testID,
|
|
onPress,
|
|
action,
|
|
showAnimation,
|
|
label,
|
|
prefix,
|
|
maxWidth,
|
|
type = 'normal',
|
|
boldText = false,
|
|
}: SelectedChipProps) {
|
|
const actionIcon = action?.icon;
|
|
const actionOnPress = action?.onPress;
|
|
|
|
const theme = useTheme();
|
|
const style = getStyleFromTheme(theme);
|
|
const dimensions = useWindowDimensions();
|
|
const textStyle = useMemo(() => {
|
|
// We set the max width to 70% of the screen width to make sure
|
|
// text like names get ellipsized correctly.
|
|
const textMaxWidth = maxWidth || dimensions.width * 0.70;
|
|
const marginRight = actionIcon ? undefined : 7;
|
|
const marginLeft = prefix ? 5 : 7;
|
|
return [
|
|
style.text,
|
|
{maxWidth: textMaxWidth, marginRight, marginLeft},
|
|
type === 'link' && style.linkText,
|
|
type === 'danger' && style.dangerText,
|
|
boldText && style.boldText,
|
|
];
|
|
}, [maxWidth, dimensions.width, actionIcon, prefix, style.text, style.linkText, style.dangerText, style.boldText, type, boldText]);
|
|
const containerStyle = useMemo(() => {
|
|
return [
|
|
style.container,
|
|
type === 'danger' && style.dangerContainer,
|
|
];
|
|
}, [style.container, style.dangerContainer, type]);
|
|
|
|
const chipContent = (
|
|
<>
|
|
{prefix}
|
|
<Text
|
|
style={textStyle}
|
|
numberOfLines={1}
|
|
testID={`${testID}.display_name`}
|
|
>
|
|
{nonBreakingString(label)}
|
|
</Text>
|
|
</>
|
|
);
|
|
|
|
let content = chipContent;
|
|
if (actionIcon) {
|
|
const iconName = actionIcon === 'remove' ? 'close-circle' : 'chevron-down';
|
|
let icon = (
|
|
<CompassIcon
|
|
name={iconName}
|
|
size={16}
|
|
color={changeOpacity(theme.centerChannelColor, 0.64)}
|
|
testID={`${testID}.${actionIcon}.icon`}
|
|
/>
|
|
);
|
|
|
|
if (actionOnPress) {
|
|
icon = (
|
|
<TouchableOpacity
|
|
style={style.remove}
|
|
onPress={actionOnPress}
|
|
testID={`${testID}.${actionIcon}.button`}
|
|
>
|
|
{icon}
|
|
</TouchableOpacity>
|
|
);
|
|
} else {
|
|
icon = (
|
|
<View style={style.remove}>
|
|
{icon}
|
|
</View>
|
|
);
|
|
}
|
|
|
|
content = (
|
|
<>
|
|
{content}
|
|
{icon}
|
|
</>
|
|
);
|
|
}
|
|
|
|
if (onPress) {
|
|
content = (
|
|
<TouchableOpacity
|
|
style={style.chipContent}
|
|
onPress={onPress}
|
|
testID={`${testID}.chip_button`}
|
|
>
|
|
{content}
|
|
</TouchableOpacity>
|
|
);
|
|
}
|
|
|
|
// https://mattermost.atlassian.net/browse/MM-63814?focusedCommentId=178584
|
|
const useFadeOut = showAnimation && Platform.OS !== 'android';
|
|
return (
|
|
<Animated.View
|
|
entering={showAnimation ? FadeIn.duration(FADE_DURATION) : undefined}
|
|
exiting={useFadeOut ? FadeOut.duration(FADE_DURATION) : undefined}
|
|
style={containerStyle}
|
|
testID={testID}
|
|
>
|
|
{content}
|
|
</Animated.View>
|
|
);
|
|
}
|