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
1 change: 1 addition & 0 deletions apps/examples/src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ const styles = css.create({
},
transitionOpacity: {
backgroundColor: 'red',
transitionDelay: '250ms',
transitionDuration: '0.5s',
transitionProperty: 'opacity',
transitionTimingFunction: 'ease'
Expand Down
20 changes: 11 additions & 9 deletions packages/react-strict-dom/src/native/modules/useStyleTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ function transitionStyleHasChanged(

function getAnimation(
animatedValue: ReactNative.Animated.Value,
delay: number,
duration: number,
timingFunction: string | null,
shouldUseNativeDriver: boolean
Expand All @@ -210,6 +211,7 @@ function getAnimation(
`spring() timing function of "${timingFunction}" is missing closing parenthesis.`
);
return ReactNative.Animated.timing(animatedValue, {
delay,
duration,
easing: getEasingFunction(null),
toValue: 1,
Expand Down Expand Up @@ -244,6 +246,7 @@ function getAnimation(
}

return ReactNative.Animated.spring(animatedValue, {
delay,
damping,
mass,
stiffness,
Expand All @@ -254,6 +257,7 @@ function getAnimation(
}

return ReactNative.Animated.timing(animatedValue, {
delay,
duration,
easing: getEasingFunction(timingFunction),
toValue: 1,
Expand Down Expand Up @@ -324,15 +328,13 @@ export function useStyleTransition(style: ReactNativeStyle): ReactNativeStyle {
const { delay, duration, timingFunction, shouldUseNativeDriver } =
transitionMetadataRef.current;

const animation = ReactNative.Animated.sequence([
ReactNative.Animated.delay(delay),
getAnimation(
animatedValue,
duration,
timingFunction,
shouldUseNativeDriver
)
]);
const animation = getAnimation(
animatedValue,
delay,
duration,
timingFunction,
shouldUseNativeDriver
);
animation.start();

return () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/react-strict-dom/tests/__mocks__/react-native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export const Animated = {
}),
timing: jest.fn(() => {
return {
start: jest.fn()
start: jest.fn((callback) => {
callback && callback();
}),
stop: jest.fn()
};
}),
delay: jest.fn(),
Expand All @@ -33,7 +36,10 @@ export const Animated = {
}),
spring: jest.fn(() => {
return {
start: jest.fn()
start: jest.fn((callback) => {
callback && callback();
}),
stop: jest.fn()
};
})
};
Expand Down
40 changes: 36 additions & 4 deletions packages/react-strict-dom/tests/html-test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ describe('<html.*>', () => {
expect(console.warn).not.toHaveBeenCalledWith(
expect.stringContaining('React Strict DOM')
);
expect(Animated.sequence).not.toHaveBeenCalled();
expect(Animated.timing).not.toHaveBeenCalled();
expect(root.toJSON()).toMatchSnapshot('default');
});

Expand All @@ -638,14 +638,14 @@ describe('<html.*>', () => {
expect(console.error).not.toHaveBeenCalledWith(
expect.stringContaining('React Strict DOM')
);
expect(Animated.sequence).toHaveBeenCalled();
expect(Animated.timing).toHaveBeenCalled();
expect(root.toJSON()).toMatchSnapshot('red to green');
Animated.sequence.mockClear();
Animated.timing.mockClear();

act(() => {
root.update(<html.div style={styles.backgroundColor('blue')} />);
});
expect(Animated.sequence).toHaveBeenCalled();
expect(Animated.timing).toHaveBeenCalled();
expect(root.toJSON()).toMatchSnapshot('green to blue');
});

Expand All @@ -664,6 +664,14 @@ describe('<html.*>', () => {
});
expect(root.toJSON()).toMatchSnapshot('end');
expect(Easing.inOut).toHaveBeenCalled();
expect(Animated.timing).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
delay: 200,
duration: 2000,
useNativeDriver: false
})
);
});

test('opacity transition', () => {
Expand All @@ -679,6 +687,14 @@ describe('<html.*>', () => {
});
expect(root.toJSON()).toMatchSnapshot('end');
expect(Easing.in).toHaveBeenCalled();
expect(Animated.timing).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
delay: 50,
duration: 1000,
useNativeDriver: true
})
);
});

test('transform transition', () => {
Expand All @@ -698,6 +714,14 @@ describe('<html.*>', () => {
});
expect(root.toJSON()).toMatchSnapshot('end');
expect(Easing.out).toHaveBeenCalled();
expect(Animated.timing).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
delay: 0,
duration: 1000,
useNativeDriver: true
})
);
});

test('width transition', () => {
Expand All @@ -713,6 +737,14 @@ describe('<html.*>', () => {
});
expect(root.toJSON()).toMatchSnapshot('end');
expect(Easing.out).toHaveBeenCalled();
expect(Animated.timing).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
delay: 0,
duration: 500,
useNativeDriver: false
})
);
});

test('cubic-bezier() timing function', () => {
Expand Down