Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions demo/src/screens/__tests__/AvatarScreen.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import renderer from 'react-test-renderer';
import renderer, {act} from 'react-test-renderer';

describe('AvatarScreen', () => {
let AvatarScreen;
Expand All @@ -9,7 +9,14 @@ describe('AvatarScreen', () => {
});

it('renders screen', () => {
const tree = renderer.create(<AvatarScreen/>).toJSON();
let testRenderer;
act(() => {
testRenderer = renderer.create(<AvatarScreen/>);
});
const tree = testRenderer.toJSON();
expect(tree).toMatchSnapshot();
act(() => {
testRenderer.unmount();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -1466,10 +1466,9 @@ exports[`AvatarScreen renders screen 1`] = `
assetGroup="icons"
onError={[Function]}
onLoad={[Function]}
onLoadStart={[Function]}
source={
{
"uri": "https://static.pexels.com/photos/60628/flower-garden-blue-sky-hokkaido-japan-60628.jpeg",
"uri": "https://lh3.googleusercontent.com/-CMM0GmT5tiI/AAAAAAAAAAI/AAAAAAAAAAA/-o9gKbC6FVo/s181-c/111308920004613908895.jpg",
}
}
style={
Expand Down
2 changes: 1 addition & 1 deletion demo/src/screens/componentScreens/AvatarsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const examples = [
size: 60,
animate: true,
imageProps: {animationDuration: 1000},
source: {uri: 'https://static.pexels.com/photos/60628/flower-garden-blue-sky-hokkaido-japan-60628.jpeg'}
source: {uri: 'https://lh3.googleusercontent.com/-CMM0GmT5tiI/AAAAAAAAAAI/AAAAAAAAAAA/-o9gKbC6FVo/s181-c/111308920004613908895.jpg'}
},
{
title: 'Big pimple',
Expand Down
19 changes: 13 additions & 6 deletions src/components/animatedImage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: consider unify this component functionality with our Image component
import React, {useState, useCallback, useMemo} from 'react';
import React, {useState, useCallback, useMemo, useEffect} from 'react';
import {StyleSheet, StyleProp, ViewStyle, NativeSyntheticEvent, ImageLoadEventData} from 'react-native';
import Animated, {useSharedValue, useAnimatedStyle, withTiming} from 'react-native-reanimated';
import View from '../../components/view';
Expand Down Expand Up @@ -51,6 +51,12 @@ const AnimatedImage = (props: AnimatedImageProps) => {
}
}, [loader]);

useEffect(() => {
setIsLoading(true);
propsOnLoadStart?.();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [source]);

const onLoad = useCallback((event: NativeSyntheticEvent<ImageLoadEventData>) => {
setIsLoading(false);
propsOnLoad?.(event);
Expand All @@ -62,10 +68,11 @@ const AnimatedImage = (props: AnimatedImageProps) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
[setIsLoading, propsOnLoad, animationDuration]);

const onLoadStart = useCallback(() => {
setIsLoading(true);
propsOnLoadStart?.();
}, [setIsLoading, propsOnLoadStart, animationDuration]);
// TODO: revert to this solution when iOS is fixed (RN77 bug)
// const onLoadStart = useCallback(() => {
// setIsLoading(true);
// propsOnLoadStart?.();
// }, [setIsLoading, propsOnLoadStart, animationDuration]);

const fadeInStyle = useAnimatedStyle(() => {
return {opacity: opacity.value};
Expand All @@ -81,7 +88,7 @@ const AnimatedImage = (props: AnimatedImageProps) => {
style={_style}
source={source}
onLoad={onLoad}
onLoadStart={onLoadStart}
// onLoadStart={onLoadStart}
testID={testID}
imageStyle={undefined}
/>
Expand Down