-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29945 from JKobrynski/migrateAnimatedStepToTypeSc…
…ript [No QA] [TS Migration] migrate AnimatedStep directory's files to TypeScript
- Loading branch information
Showing
5 changed files
with
37 additions
and
41 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React, {createContext} from 'react'; | ||
import {ValueOf} from 'type-fest'; | ||
import CONST from '@src/CONST'; | ||
|
||
type AnimationDirection = ValueOf<typeof CONST.ANIMATION_DIRECTION>; | ||
|
||
type StepContext = { | ||
animationDirection: AnimationDirection; | ||
setAnimationDirection: React.Dispatch<React.SetStateAction<AnimationDirection>>; | ||
}; | ||
|
||
const AnimatedStepContext = createContext<StepContext | null>(null); | ||
|
||
export default AnimatedStepContext; | ||
export type {StepContext, AnimationDirection}; |
14 changes: 5 additions & 9 deletions
14
...ents/AnimatedStep/AnimatedStepProvider.js → ...nts/AnimatedStep/AnimatedStepProvider.tsx
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 |
---|---|---|
@@ -1,18 +1,14 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, {useMemo, useState} from 'react'; | ||
import CONST from '@src/CONST'; | ||
import AnimatedStepContext from './AnimatedStepContext'; | ||
import ChildrenProps from '@src/types/utils/ChildrenProps'; | ||
import AnimatedStepContext, {AnimationDirection} from './AnimatedStepContext'; | ||
|
||
const propTypes = { | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
function AnimatedStepProvider({children}) { | ||
const [animationDirection, setAnimationDirection] = useState(CONST.ANIMATION_DIRECTION.IN); | ||
function AnimatedStepProvider({children}: ChildrenProps): React.ReactNode { | ||
const [animationDirection, setAnimationDirection] = useState<AnimationDirection>(CONST.ANIMATION_DIRECTION.IN); | ||
const contextValue = useMemo(() => ({animationDirection, setAnimationDirection}), [animationDirection, setAnimationDirection]); | ||
|
||
return <AnimatedStepContext.Provider value={contextValue}>{children}</AnimatedStepContext.Provider>; | ||
} | ||
|
||
AnimatedStepProvider.propTypes = propTypes; | ||
AnimatedStepProvider.displayName = 'AnimatedStepProvider'; | ||
export default AnimatedStepProvider; |
40 changes: 15 additions & 25 deletions
40
src/components/AnimatedStep/index.js → src/components/AnimatedStep/index.tsx
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 |
---|---|---|
@@ -1,62 +1,52 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import {StyleProp, ViewStyle} from 'react-native'; | ||
import * as Animatable from 'react-native-animatable'; | ||
import useNativeDriver from '@libs/useNativeDriver'; | ||
import styles from '@styles/styles'; | ||
import CONST from '@src/CONST'; | ||
import ChildrenProps from '@src/types/utils/ChildrenProps'; | ||
import {AnimationDirection} from './AnimatedStepContext'; | ||
|
||
const propTypes = { | ||
/** Children to wrap in AnimatedStep. */ | ||
children: PropTypes.node.isRequired, | ||
|
||
type AnimatedStepProps = ChildrenProps & { | ||
/** Styles to be assigned to Container */ | ||
// eslint-disable-next-line react/forbid-prop-types | ||
style: PropTypes.arrayOf(PropTypes.object), | ||
style: StyleProp<ViewStyle>; | ||
|
||
/** Whether we're animating the step in or out */ | ||
direction: PropTypes.oneOf(['in', 'out']), | ||
direction: AnimationDirection; | ||
|
||
/** Callback to fire when the animation ends */ | ||
onAnimationEnd: PropTypes.func, | ||
}; | ||
|
||
const defaultProps = { | ||
direction: 'in', | ||
style: [], | ||
onAnimationEnd: () => {}, | ||
onAnimationEnd: () => void; | ||
}; | ||
|
||
function getAnimationStyle(direction) { | ||
function getAnimationStyle(direction: AnimationDirection) { | ||
let transitionValue; | ||
|
||
if (direction === 'in') { | ||
transitionValue = CONST.ANIMATED_TRANSITION_FROM_VALUE; | ||
} else if (direction === 'out') { | ||
} else { | ||
transitionValue = -CONST.ANIMATED_TRANSITION_FROM_VALUE; | ||
} | ||
return styles.makeSlideInTranslation('translateX', transitionValue); | ||
} | ||
|
||
function AnimatedStep(props) { | ||
function AnimatedStep({onAnimationEnd, direction = CONST.ANIMATION_DIRECTION.IN, style = [], children}: AnimatedStepProps) { | ||
return ( | ||
<Animatable.View | ||
onAnimationEnd={() => { | ||
if (!props.onAnimationEnd) { | ||
if (!onAnimationEnd) { | ||
return; | ||
} | ||
props.onAnimationEnd(); | ||
onAnimationEnd(); | ||
}} | ||
duration={CONST.ANIMATED_TRANSITION} | ||
animation={getAnimationStyle(props.direction)} | ||
animation={getAnimationStyle(direction)} | ||
useNativeDriver={useNativeDriver} | ||
style={props.style} | ||
style={style} | ||
> | ||
{props.children} | ||
{children} | ||
</Animatable.View> | ||
); | ||
} | ||
|
||
AnimatedStep.propTypes = propTypes; | ||
AnimatedStep.defaultProps = defaultProps; | ||
AnimatedStep.displayName = 'AnimatedStep'; | ||
export default AnimatedStep; |
4 changes: 2 additions & 2 deletions
4
...ts/AnimatedStep/useAnimatedStepContext.js → ...ts/AnimatedStep/useAnimatedStepContext.ts
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