Update image gallery button to use TypeScript

This commit is contained in:
Arnaud Vergnet 2020-09-22 11:52:17 +02:00
parent 98518c46b6
commit 18f8c64302

View file

@ -17,33 +17,29 @@
* along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
*/ */
// @flow
import * as React from 'react'; import * as React from 'react';
import {TouchableRipple} from 'react-native-paper'; import {TouchableRipple} from 'react-native-paper';
import {StackNavigationProp} from '@react-navigation/stack';
import {Image} from 'react-native-animatable'; import {Image} from 'react-native-animatable';
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet'; import {useNavigation} from '@react-navigation/native';
import {ViewStyle} from 'react-native';
type PropsType = { type PropsType = {
navigation: StackNavigationProp, images: Array<{url: string}>;
images: Array<{url: string}>, style: ViewStyle;
style: ViewStyleProp,
}; };
class ImageGalleryButton extends React.Component<PropsType> { function ImageGalleryButton(props: PropsType) {
onPress = () => { const navigation = useNavigation();
const {navigation, images} = this.props;
navigation.navigate('gallery', {images}); const onPress = () => {
navigation.navigate('gallery', {images: props.images});
}; };
render(): React.Node {
const {style, images} = this.props;
return ( return (
<TouchableRipple onPress={this.onPress} style={style}> <TouchableRipple onPress={onPress} style={props.style}>
<Image <Image
resizeMode="contain" resizeMode="contain"
source={{uri: images[0].url}} source={{uri: props.images[0].url}}
style={{ style={{
width: '100%', width: '100%',
height: '100%', height: '100%',
@ -52,6 +48,5 @@ class ImageGalleryButton extends React.Component<PropsType> {
</TouchableRipple> </TouchableRipple>
); );
} }
}
export default ImageGalleryButton; export default ImageGalleryButton;