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

Refactor rn movable view #1639

Open
wants to merge 107 commits into
base: master
Choose a base branch
from
Open

Conversation

yandadaFreedom
Copy link
Collaborator

No description provided.

const eventHandlers: Record<string, any> = {}
const catchEventList = [
{ name: 'onTouchStart', value: ['catchtouchstart'] },
{ name: 'onTouchMove', value: ['catchtouchmove', 'catchvtouchmove', 'catchvhouchmove'] },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catchvhouchmove写错了

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是movable专用就放movable里面


const getValue = () => {
const getValue = useCallback(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这层包装没有意义啊

groupValue,
notifyChange
}
}, [notifyChange])
Copy link
Collaborator

@hiyuki hiyuki Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

传空依赖就行

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以及感觉包在一个大的useMemo里就可以,前面都不需要写useCallback

submit,
reset
}
}, [submit, reset])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该传空依赖就行

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,一个大memo搞定

@@ -69,10 +71,11 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
triggerChange: noop
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个得意义是啥?

const contextValue = useMemo(() => ({
height: style.height || 10,
width: style.width || 10
}), [style.width, style.height])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥不监听normalStyle的值

import useNodesRef, { HandlerRef } from './useNodesRef'
import { MovableAreaContext } from './context'
import { useTransformStyle, splitProps, splitStyle, DEFAULT_UNLAY_STYLE, wrapChildren, GestureHandler, flatGesture } from './utils'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个DEFAULT_UNLAY_STYLE改名为HIDDEN_STYLE吧

const gesture = useMemo(() => {
return Gesture.Pan()
.onTouchesDown((e: GestureTouchEvent) => {
'worklet'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接回调里应该不用写worklet

}
})
.withRef(movableGestureRef)
}, [disabled, direction, inertia, outOfBounds, handleTriggerMove, handleTriggerStart, handleTriggerEnd])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里面有些依赖是必定变化的,会导致memo失效,不用重新执行的逻辑可以考虑都放在一个大memo中

<Animated.View
ref={nodeRef}
onLayout={onLayout}
style={[styles.container, innerStyle, animatedStyles, layoutStyle]}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultStyle可以在早期合入

useNodesRef(props, ref, nodeRef, {
defaultStyle: styles.container
defaultStyle: styles.container,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方defaultStyle不用传递了,把normalStyle作为style传递进去就可以,内部的getComputedStyle也直接使用这里传递的normalStyle,而不需要读取props.style了

}
}
if (simultaneousHandlers && simultaneousHandlers.length) {
gesture.simultaneousWithExternalGesture(...simultaneousHandlers)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里得考虑清空之前的注册,否则会无限累加

if (gesture?.nodeRefs) {
return gesture.nodeRefs
.map((item: { getNodeInstance: () => any }) => item.getNodeInstance()?.instance?.gestureRef || {})
.filter(Boolean)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是啥意思啊

}

export function flatGesture (gestures?: Array<GestureHandler>) {
return gestures && gestures.flatMap((gesture: GestureHandler) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个flatMap在哪定义的?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants