Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: and cancel method to useAnimationState() and useDynamicAnimation() #367

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
4 changes: 3 additions & 1 deletion packages/moti/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
ImageStyle,
TextStyle,
ViewStyle,

} from 'react-native'
import type {
SharedValue,
Expand Down Expand Up @@ -462,6 +461,7 @@ export type UseAnimationState<V> = {
* ```
*/
transitionTo: (key: keyof V | ((currentState: keyof V) => keyof V)) => void
cancel: () => void
}

export type UseAnimationStateConfig<
Expand Down Expand Up @@ -545,6 +545,8 @@ export type UseDynamicAnimationState<Animate = FallbackAnimateProp> = {
| DynamicStyleProp<Animate>
| ((currentState: DynamicStyleProp<Animate>) => DynamicStyleProp<Animate>)
) => void

cancel: () => void
}

export type ExcludeFunctionKeys<T> = {
Expand Down
5 changes: 4 additions & 1 deletion packages/moti/src/core/use-animator/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef } from 'react'
import { useSharedValue } from 'react-native-reanimated'
import { cancelAnimation, useSharedValue } from 'react-native-reanimated'
import { PackageName } from '../constants'
import type {
InternalControllerState,
Expand Down Expand Up @@ -176,6 +176,9 @@ export default function useAnimationState<V extends Variants<V>>(
get current(): keyof V {
return selectedVariant.current
},
cancel() {
cancelAnimation(__state)
},
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/moti/src/core/use-dynamic-animation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
ExcludeFunctionKeys,
UseDynamicAnimationState,
} from '../types'
import { useSharedValue } from 'react-native-reanimated'
import { useSharedValue, cancelAnimation } from 'react-native-reanimated'
import { useRef } from 'react'
import { ViewStyle, TextStyle, ImageStyle } from 'react-native'

Expand Down Expand Up @@ -69,6 +69,9 @@ export default function useDynamicAnimation<

__state.value = nextStyle
},
cancel() {
cancelAnimation(__state)
},
}
}

Expand Down
Loading