mattermost-mobile-upstream/app/components/progress_bar/index.tsx
Elias Nahum b6fc85385e
Migrate from RNN to Expo router (#9402)
* 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
2026-05-13 17:44:55 +08:00

164 lines
5.1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useCallback, useEffect} from 'react';
import {type LayoutChangeEvent, type StyleProp, View, type ViewStyle, StyleSheet} from 'react-native';
import {Gesture, GestureDetector} from 'react-native-gesture-handler';
import Animated, {clamp, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import {scheduleOnRN} from 'react-native-worklets';
import {useTheme} from '@context/theme';
import {changeOpacity} from '@utils/theme';
type ProgressBarProps = {
color: string;
containerStyle?: StyleProp<ViewStyle>;
progress: number;
withCursor?: boolean;
style?: StyleProp<ViewStyle>;
onSeek?: (position: number) => void;
}
const styles = StyleSheet.create({
container: {
position: 'relative',
justifyContent: 'center',
paddingVertical: 10,
},
progressBarContainer: {
height: 4,
borderRadius: 2,
overflow: 'hidden',
width: '100%',
},
progressBar: {
flex: 1,
},
cursor: {
position: 'absolute',
borderRadius: 100,
width: 15,
height: 15,
},
});
const START_CURSOR_VALUE = 0;
const END_CURSOR_VALUE = 1;
const ProgressBar = ({color, containerStyle, progress, withCursor, style, onSeek}: ProgressBarProps) => {
const theme = useTheme();
const widthValue = useSharedValue(0);
const progressValue = useSharedValue(progress);
const isGestureActive = useSharedValue(false);
const panGesture = Gesture.Pan().
onStart(() => {
isGestureActive.value = true;
}).
onChange((e) => {
if (onSeek) {
const clampedSeekPosition = clamp(e.x / widthValue.value, START_CURSOR_VALUE, END_CURSOR_VALUE);
scheduleOnRN(onSeek, clampedSeekPosition);
}
}).
onEnd(() => {
isGestureActive.value = false;
}).
onFinalize(() => {
isGestureActive.value = false;
});
const tapGesture = Gesture.Tap().
onStart(() => {
isGestureActive.value = true;
}).
onEnd((e) => {
if (onSeek) {
const clampedSeekPosition = clamp(e.x / widthValue.value, START_CURSOR_VALUE, END_CURSOR_VALUE);
scheduleOnRN(onSeek, clampedSeekPosition);
}
isGestureActive.value = false;
}).
onFinalize(() => {
isGestureActive.value = false;
});
const composedGestures = Gesture.Race(tapGesture, panGesture);
const progressAnimatedStyle = useAnimatedStyle(() => {
const translateX = ((progressValue.value * 0.5) - 0.5) * widthValue.value;
const scaleX = progressValue.value ? progressValue.value : 0.0001;
return {
transform: [
{translateX: isGestureActive.value ? translateX : withTiming(translateX, {duration: 200})},
{scaleX: isGestureActive.value ? scaleX : withTiming(scaleX, {duration: 200})},
],
width: widthValue.value,
};
});
const cursorAnimatedStyle = useAnimatedStyle(() => {
const cursorWidth = 15;
const leftPosition = (progressValue.value * widthValue.value) - (cursorWidth / 2);
return {
left: isGestureActive.value ? leftPosition : withTiming(leftPosition, {duration: 100}),
};
});
useEffect(() => {
progressValue.value = progress;
// Update the shared value only when the progress changes.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [progress]);
const onLayout = useCallback((e: LayoutChangeEvent) => {
widthValue.value = e.nativeEvent.layout.width;
}, [widthValue]);
return (
<GestureDetector gesture={composedGestures}>
<View
onTouchStart={(e) => e.stopPropagation()}
style={[styles.container, containerStyle]}
>
<View
onLayout={onLayout}
style={[
styles.progressBarContainer,
{
backgroundColor: withCursor ? changeOpacity(theme.centerChannelColor, 0.2) : 'rgba(255, 255, 255, 0.16)',
},
style,
]}
>
<Animated.View
style={[
styles.progressBar,
{
backgroundColor: color,
},
progressAnimatedStyle,
]}
/>
</View>
{withCursor &&
<Animated.View
style={[
styles.cursor,
{
backgroundColor: color,
},
cursorAnimatedStyle,
]}
/>}
</View>
</GestureDetector>
);
};
export default ProgressBar;