Skip to content

Commit

Permalink
fix crash bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dukenv0307 committed Jan 26, 2024
1 parent 7fce375 commit 6939350
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/components/Image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import RESIZE_MODES from './resizeModes';

function Image(props) {
const {source: propsSource, isAuthTokenRequired, onLoad, session} = props;
const [aspectRatio, setAspectRatio] = useState();
const [aspectRatio, setAspectRatio] = useState(null);
/**
* Check if the image source is a URL - if so the `encryptedAuthToken` is appended
* to the source.
Expand Down Expand Up @@ -54,7 +54,7 @@ function Image(props) {
// eslint-disable-next-line react/jsx-props-no-spreading
{...forwardedProps}
source={source}
style={[forwardedProps.style, aspectRatio !== undefined && {aspectRatio, height: 'auto'}, props.objectPositionTop && !aspectRatio && {opacity: 0}]}
style={[forwardedProps.style, !!aspectRatio && {aspectRatio, height: 'auto'}, props.objectPositionTop && !aspectRatio && {opacity: 0}]}
/>
);
}
Expand Down
26 changes: 4 additions & 22 deletions src/components/Image/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,6 @@ function Image(props) {
};
}

const newSource = useMemo(() => {
if (isAuthTokenRequired) {
const authToken = lodashGet(session, 'encryptedAuthToken', null);
return {uri: `${source.uri}?encryptedAuthToken=${encodeURIComponent(authToken)}`};
}
return source;
}, [source, isAuthTokenRequired, session]);

useEffect(() => {
if (props.onLoad == null) {
return;
}
RNImage.getSize(newSource.uri, (width, height) => {
props.onLoad({nativeEvent: {width, height}});

if (props.objectPositionTop) {
setAspectRatio(height ? width / height : 'auto');
}
});
}, [props.onLoad, newSource, props]);

return (
<ImageComponent
// eslint-disable-next-line react/jsx-props-no-spreading
Expand All @@ -67,8 +46,11 @@ function Image(props) {
if (props.onLoad) {
props.onLoad({nativeEvent: {width, height}});
}
if (props.objectPositionTop) {
setAspectRatio(height ? width / height : 'auto');
}
}}
style={[props.style, aspectRatio !== undefined && {aspectRatio, height: 'auto'}, props.objectPositionTop && !aspectRatio && {opacity: 0}]}
style={[props.style, !!aspectRatio && {aspectRatio, height: 'auto'}, props.objectPositionTop && !aspectRatio && {opacity: 0}]}
/>
);
}
Expand Down

0 comments on commit 6939350

Please sign in to comment.