mattermost-mobile/app/components/progress_bar.tsx
Elias Nahum dbd7bc8a51
Gallery Improvements (#4837)
* Open/Close Gallery transitions

* Include postId in file info & disable opening the gallery in some cases

* Add progress bar component

* Transition to gallery based on platform

* Improve getting the filename for non attachments

* Patch RNFetchBlob TS definition

* Add gallery types

* fix unit tests for message and post attachment

* add getLocalPath method

* Add react-native-share dependency

* Re-style gallery footer

* Refactor Gallery screen

* Double tap zoom in/out and translate

* Make android activity "transparent"

* Do not animate to height on dismissing gallery

* Open gallery for file uploads

* Fix borderRadius for gallery action button

* Use progress bar for file uploads

* Replace progress bar for file attachment document

* Upgrade RNN to 7.1.0 to fix share elements transitions

* Fix Gallery unit tests

* translate down when popping screen on iOS

* Swipe, Pan & Tap fixes

* fix gallery footer avatar eslint

* Fix gallery snapshot tests

* Use CompassIcon in Gallery

* Feedback from UX review

* Fix gallery UI for other file types

* Set other file type gallery button to 48pt
2020-11-06 21:17:27 -03:00

77 lines
2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {Animated, LayoutChangeEvent, StyleSheet, StyleProp, View, ViewStyle} from 'react-native';
type ProgressBarProps = {
color: string;
progress: number;
style?: StyleProp<ViewStyle>;
}
const styles = StyleSheet.create({
container: {
height: 4,
borderRadius: 2,
backgroundColor: 'rgba(255, 255, 255, 0.16)',
overflow: 'hidden',
width: '100%',
},
progressBar: {
flex: 1,
},
});
const ProgressBar = ({color, progress, style}: ProgressBarProps) => {
const timer = useRef(new Animated.Value(progress)).current;
const [width, setWidth] = useState(0);
useEffect(() => {
const animation = Animated.timing(timer, {
duration: 200,
useNativeDriver: true,
isInteraction: false,
toValue: progress,
});
animation.start();
return animation.stop;
}, [progress]);
const onLayout = useCallback((e: LayoutChangeEvent) => {
setWidth(e.nativeEvent.layout.width);
}, []);
const translateX = timer.interpolate({
inputRange: [0, 1],
outputRange: [(-0.5 * width), 0],
});
const scaleX = timer.interpolate({
inputRange: [0, 1],
outputRange: [0.0001, 1],
});
return (
<View
onLayout={onLayout}
style={[styles.container, style]}
>
<Animated.View
style={[
styles.progressBar, {
backgroundColor: color,
width,
transform: [
{translateX},
{scaleX},
],
},
]}
/>
</View>
);
};
export default ProgressBar;