-
-
Notifications
You must be signed in to change notification settings - Fork 24
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: improve pan interaction and animation state management #51
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,21 @@ import type { Options } from '@/types' | |
import { invariant } from 'hey-listen' | ||
import { setTarget } from 'framer-motion/dist/es/render/utils/setters.mjs' | ||
import type { VisualElement } from 'framer-motion' | ||
import { resolveVariant } from '@/state/utils' | ||
|
||
function stopAnimation(visualElement: VisualElement) { | ||
visualElement.values.forEach(value => value.stop()) | ||
} | ||
|
||
function setStateTarget(state: MotionState, definition: Options['animate']) { | ||
const resolvedVariant = resolveVariant(definition, state.options.variants, state.options.custom) | ||
Object.entries(resolvedVariant).forEach(([key, value]) => { | ||
if (key === 'transition') | ||
return | ||
state.target[key] = value | ||
}) | ||
} | ||
|
||
/** | ||
* @public | ||
*/ | ||
|
@@ -85,6 +95,7 @@ export function setValues( | |
return setVariants(state, [definition]) | ||
} | ||
else { | ||
setStateTarget(state, definition) | ||
setTarget(state.visualElement, definition as any) | ||
} | ||
} | ||
|
@@ -95,7 +106,7 @@ function setVariants(state: MotionState, variantLabels: string[]) { | |
reversedLabels.forEach((key) => { | ||
const variant = visualElement.getVariant(key) | ||
variant && setTarget(visualElement, variant) | ||
|
||
setStateTarget(state, variant) | ||
if (visualElement.variantChildren) { | ||
visualElement.variantChildren.forEach((child) => { | ||
setVariants(mountedStates.get(child.current as HTMLElement), variantLabels) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The recursive call to |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,8 +117,8 @@ function createAnimationFactories( | |
): AnimationFactory[] { | ||
const factories: AnimationFactory[] = [] | ||
|
||
new Set(Object.keys(this.target)).forEach((key: any) => { | ||
if (!hasChanged(this.visualElement.getValue(key), this.target[key])) | ||
Object.keys(this.target).forEach((key: any) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable Suggested Change: Object.keys(this.target).forEach((key: keyof typeof this.target) => {...}) |
||
if (!hasChanged(prevTarget[key], this.target[key])) | ||
return | ||
|
||
this.baseTarget[key] ??= style.get(this.element, key) as string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The line assumes that Suggested Change: this.baseTarget[key] ??= style.get(this.element, key) as string | undefined |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
definition as any
in thesetTarget
function call is a type assertion that bypasses TypeScript's static type checking. This could lead to runtime errors ifdefinition
does not meet the expected structure required bysetTarget
. To improve type safety and maintainability, consider validatingdefinition
or refining its type definition to ensure it aligns with whatsetTarget
expects.