11import React , { PureComponent } from 'react' ;
22import PropTypes from 'prop-types' ;
33import {
4- View , Pressable ,
4+ View , Image , Pressable ,
55} from 'react-native' ;
6- import { withOnyx } from 'react-native-onyx' ;
7- import FastImage from '../FastImage' ;
86import styles from '../../styles/styles' ;
97import * as StyleUtils from '../../styles/StyleUtils' ;
108import canUseTouchScreen from '../../libs/canUseTouchscreen' ;
119import withWindowDimensions , { windowDimensionsPropTypes } from '../withWindowDimensions' ;
1210import FullscreenLoadingIndicator from '../FullscreenLoadingIndicator' ;
13- import compose from '../../libs/compose' ;
14- import ONYXKEYS from '../../ONYXKEYS' ;
15- import chatAttachmentTokenHeaders from '../../libs/chatAttachmentTokenHeaders' ;
1611
1712const propTypes = {
18-
19- /** Do the urls require an authToken? */
20- isAuthTokenRequired : PropTypes . bool ,
21-
2213 /** URL to full-sized image */
2314 url : PropTypes . string . isRequired ,
2415 ...windowDimensionsPropTypes ,
2516} ;
2617
27- const defaultProps = {
28- isAuthTokenRequired : false ,
29- } ;
30-
3118class ImageView extends PureComponent {
3219 constructor ( props ) {
3320 super ( props ) ;
@@ -36,7 +23,6 @@ class ImageView extends PureComponent {
3623 this . onContainerLayoutChanged = this . onContainerLayoutChanged . bind ( this ) ;
3724 this . onContainerPressIn = this . onContainerPressIn . bind ( this ) ;
3825 this . onContainerPress = this . onContainerPress . bind ( this ) ;
39- this . imageLoad = this . imageLoad . bind ( this ) ;
4026 this . imageLoadingStart = this . imageLoadingStart . bind ( this ) ;
4127 this . imageLoadingEnd = this . imageLoadingEnd . bind ( this ) ;
4228 this . trackMovement = this . trackMovement . bind ( this ) ;
@@ -60,6 +46,9 @@ class ImageView extends PureComponent {
6046 }
6147
6248 componentDidMount ( ) {
49+ Image . getSize ( this . props . url , ( width , height ) => {
50+ this . setImageRegion ( width , height ) ;
51+ } ) ;
6352 if ( this . canUseTouchScreen ) {
6453 return ;
6554 }
@@ -218,10 +207,6 @@ class ImageView extends PureComponent {
218207 this . setState ( prevState => ( { isDragging : prevState . isMouseDown } ) ) ;
219208 }
220209
221- imageLoad ( { nativeEvent} ) {
222- this . setImageRegion ( nativeEvent . width , nativeEvent . height ) ;
223- }
224-
225210 imageLoadingStart ( ) {
226211 this . setState ( { isLoading : true } ) ;
227212 }
@@ -231,29 +216,24 @@ class ImageView extends PureComponent {
231216 }
232217
233218 render ( ) {
234- const headers = this . props . isAuthTokenRequired ? chatAttachmentTokenHeaders ( ) : undefined ;
235219 if ( this . canUseTouchScreen ) {
236220 return (
237221 < View
238222 style = { [ styles . imageViewContainer , styles . overflowHidden ] }
239223 onLayout = { this . onContainerLayoutChanged }
240224 >
241- < FastImage
242- source = { {
243- uri : this . props . url ,
244- headers,
245- } }
225+ < Image
226+ source = { { uri : this . props . url } }
246227 style = { this . state . zoomScale === 0 ? undefined : [
247228 styles . w100 ,
248229 styles . h100 ,
249230 ] } // Hide image until zoomScale calculated to prevent showing preview with wrong dimensions.
250231
251232 // When Image dimensions are lower than the container boundary(zoomscale <= 1), use `contain` to render the image with natural dimensions.
252233 // Both `center` and `contain` keeps the image centered on both x and y axis.
253- resizeMode = { this . state . zoomScale > 1 ? FastImage . resizeMode . center : FastImage . resizeMode . contain }
234+ resizeMode = { this . state . zoomScale > 1 ? ' center' : ' contain' }
254235 onLoadStart = { this . imageLoadingStart }
255236 onLoadEnd = { this . imageLoadingEnd }
256- onLoad = { this . imageLoad }
257237 />
258238 { this . state . isLoading && (
259239 < FullscreenLoadingIndicator
@@ -285,19 +265,15 @@ class ImageView extends PureComponent {
285265 onPressIn = { this . onContainerPressIn }
286266 onPress = { this . onContainerPress }
287267 >
288- < FastImage
289- source = { {
290- uri : this . props . url ,
291- headers,
292- } }
268+ < Image
269+ source = { { uri : this . props . url } }
293270 style = { this . state . zoomScale === 0 ? undefined : [
294271 styles . h100 ,
295272 styles . w100 ,
296273 ] } // Hide image until zoomScale calculated to prevent showing preview with wrong dimensions.
297- resizeMode = { FastImage . resizeMode . contain }
274+ resizeMode = " contain"
298275 onLoadStart = { this . imageLoadingStart }
299276 onLoadEnd = { this . imageLoadingEnd }
300- onLoad = { this . imageLoad }
301277 />
302278 </ Pressable >
303279
@@ -312,7 +288,4 @@ class ImageView extends PureComponent {
312288}
313289
314290ImageView . propTypes = propTypes ;
315- ImageView . defaultProps = defaultProps ;
316- export default compose ( withWindowDimensions , withOnyx ( {
317- session : { key : ONYXKEYS . SESSION } ,
318- } ) ) ( ImageView ) ;
291+ export default withWindowDimensions ( ImageView ) ;
0 commit comments