From b2928049b2c5523613f0fbc562b5961f07a3a120 Mon Sep 17 00:00:00 2001 From: MrLoh Date: Sun, 22 Oct 2017 22:58:16 +0200 Subject: [PATCH] refactor(image-zoom.component): use styled-components --- src/components/image-zoom.component.js | 95 ++++++++++++-------------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/src/components/image-zoom.component.js b/src/components/image-zoom.component.js index 21b4394f6..1d6d13690 100644 --- a/src/components/image-zoom.component.js +++ b/src/components/image-zoom.component.js @@ -1,35 +1,46 @@ import React, { Component } from 'react'; -import { - StyleSheet, - Image, - View, - Modal, - Dimensions, - TouchableOpacity, - TouchableHighlight, -} from 'react-native'; +import { Image, Modal, Dimensions } from 'react-native'; import { Icon } from 'react-native-elements'; +import styled from 'styled-components/native'; import PhotoView from 'react-native-photo-view'; import { colors } from 'config'; -const styles = StyleSheet.create({ - touchable: { - justifyContent: 'center', - alignItems: 'center', - }, - modalContainer: { - flex: 1, - backgroundColor: colors.black, - justifyContent: 'center', - alignItems: 'center', - }, - closeButton: { - position: 'absolute', - top: 30, - right: 10, - }, -}); +const Touchable = styled.TouchableHighlight` + justify-content: center; + align-items: center; +`; + +const ModalContainer = styled.View` + flex: 1; + background-color: ${colors.black}; + justify-content: center; + align-items: center; +`; + +const StyledPhotoView = styled(PhotoView).attrs({ + resizeMode: 'contain', + minimumZoomScale: 0.5, + maximumZoomScale: 3, +})` + width: ${Dimensions.get('window').width}px; + height: ${Dimensions.get('window').height}px; +`; + +const CloseButton = styled.TouchableOpacity.attrs({ + activeOpacity: 0.5, +})` + position: absolute; + top: 30px; + right: 10px; +`; + +const CloseIcon = styled(Icon).attrs({ + color: colors.white, + size: 28, + name: 'x', + type: 'octicon', +})``; export class ImageZoom extends Component { props: { @@ -53,42 +64,26 @@ export class ImageZoom extends Component { } render() { - const window = Dimensions.get('window'); const { uri, style } = this.props; if (this.state.imgZoom) { return ( this.closeModal()}> - - this.closeModal()} - source={uri} - minimumZoomScale={0.5} - maximumZoomScale={3} - style={{ width: window.width, height: window.height }} - /> + + this.closeModal()} source={uri} /> - this.closeModal()} - style={styles.closeButton} - > - - - + this.closeModal()}> + + + ); } return ( - this.openModal()} - underlayColor="transparent" - style={styles.touchable} - > + this.openModal()} underlayColor="transparent"> - + ); } }