-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 0.76 stable tweaks (#1682)
- Loading branch information
1 parent
0305877
commit a60ce28
Showing
29 changed files
with
204 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as React from 'react'; | ||
import { Animated, ViewStyle } from 'react-native'; | ||
|
||
type AnimatedViewProps = { | ||
fadeInDuration?: number; | ||
style?: ViewStyle; | ||
children: React.ReactNode; | ||
useNativeDriver?: boolean; | ||
}; | ||
|
||
export function AnimatedView(props: AnimatedViewProps) { | ||
const fadeAnim = React.useRef(new Animated.Value(0)).current; // Initial value for opacity: 0 | ||
|
||
React.useEffect(() => { | ||
Animated.timing(fadeAnim, { | ||
toValue: 1, | ||
duration: props.fadeInDuration ?? 250, | ||
useNativeDriver: props.useNativeDriver ?? true, | ||
}).start(); | ||
}, [fadeAnim]); | ||
|
||
return ( | ||
<Animated.View | ||
style={{ | ||
...props.style, | ||
opacity: fadeAnim, | ||
}} | ||
> | ||
{props.children} | ||
</Animated.View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { act, render, screen } from '@testing-library/react-native'; | ||
import { AnimatedView } from '../AnimatedView'; | ||
|
||
describe('AnimatedView', () => { | ||
beforeEach(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('should use native driver when useNativeDriver is true', async () => { | ||
render( | ||
<AnimatedView fadeInDuration={250} useNativeDriver={true}> | ||
Test | ||
</AnimatedView>, | ||
); | ||
expect(screen.root).toHaveStyle({ opacity: 0 }); | ||
|
||
await act(() => jest.advanceTimersByTime(250)); | ||
expect(screen.root).toHaveStyle({ opacity: 1 }); | ||
}); | ||
|
||
it('should not use native driver when useNativeDriver is false', async () => { | ||
render( | ||
<AnimatedView fadeInDuration={250} useNativeDriver={false}> | ||
Test | ||
</AnimatedView>, | ||
); | ||
expect(screen.root).toHaveStyle({ opacity: 0 }); | ||
|
||
await act(() => jest.advanceTimersByTime(250)); | ||
expect(screen.root).toHaveStyle({ opacity: 1 }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as React from 'react'; | ||
import { Animated, ViewStyle } from 'react-native'; | ||
import { act, render, screen } from '..'; | ||
|
||
type AnimatedViewProps = { | ||
fadeInDuration?: number; | ||
style?: ViewStyle; | ||
children: React.ReactNode; | ||
useNativeDriver?: boolean; | ||
}; | ||
|
||
function AnimatedView(props: AnimatedViewProps) { | ||
const fadeAnim = React.useRef(new Animated.Value(0)).current; // Initial value for opacity: 0 | ||
|
||
React.useEffect(() => { | ||
Animated.timing(fadeAnim, { | ||
toValue: 1, | ||
duration: props.fadeInDuration ?? 250, | ||
useNativeDriver: props.useNativeDriver ?? true, | ||
}).start(); | ||
}, [fadeAnim, props.fadeInDuration, props.useNativeDriver]); | ||
|
||
return ( | ||
<Animated.View | ||
style={{ | ||
...props.style, | ||
opacity: fadeAnim, | ||
}} | ||
> | ||
{props.children} | ||
</Animated.View> | ||
); | ||
} | ||
|
||
describe('AnimatedView', () => { | ||
beforeEach(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('should use native driver when useNativeDriver is true', async () => { | ||
render( | ||
<AnimatedView fadeInDuration={250} useNativeDriver={true}> | ||
Test | ||
</AnimatedView>, | ||
); | ||
expect(screen.root).toHaveStyle({ opacity: 0 }); | ||
|
||
await act(() => jest.advanceTimersByTime(250)); | ||
expect(screen.root).toHaveStyle({ opacity: 1 }); | ||
}); | ||
|
||
it('should not use native driver when useNativeDriver is false', async () => { | ||
render( | ||
<AnimatedView fadeInDuration={250} useNativeDriver={false}> | ||
Test | ||
</AnimatedView>, | ||
); | ||
expect(screen.root).toHaveStyle({ opacity: 0 }); | ||
|
||
await act(() => jest.advanceTimersByTime(250)); | ||
expect(screen.root).toHaveStyle({ opacity: 1 }); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.