-
Notifications
You must be signed in to change notification settings - Fork 375
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
base: master
Are you sure you want to change the base?
Refactor rn movable view #1639
Conversation
…into refactor-rn-movable-view
… into feat-rn-comps-perf-events
const eventHandlers: Record<string, any> = {} | ||
const catchEventList = [ | ||
{ name: 'onTouchStart', value: ['catchtouchstart'] }, | ||
{ name: 'onTouchMove', value: ['catchtouchmove', 'catchvtouchmove', 'catchvhouchmove'] }, |
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.
catchvhouchmove写错了
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.
如果是movable专用就放movable里面
|
||
const getValue = () => { | ||
const getValue = useCallback(() => { |
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.
这层包装没有意义啊
groupValue, | ||
notifyChange | ||
} | ||
}, [notifyChange]) |
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.
传空依赖就行
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.
以及感觉包在一个大的useMemo里就可以,前面都不需要写useCallback
submit, | ||
reset | ||
} | ||
}, [submit, reset]) |
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.
应该传空依赖就行
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.
同上,一个大memo搞定
@@ -69,10 +71,11 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>( | |||
triggerChange: noop |
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.
这个得意义是啥?
const contextValue = useMemo(() => ({ | ||
height: style.height || 10, | ||
width: style.width || 10 | ||
}), [style.width, style.height]) |
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.
为啥不监听normalStyle的值
import useNodesRef, { HandlerRef } from './useNodesRef' | ||
import { MovableAreaContext } from './context' | ||
import { useTransformStyle, splitProps, splitStyle, DEFAULT_UNLAY_STYLE, wrapChildren, GestureHandler, flatGesture } from './utils' |
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.
这个DEFAULT_UNLAY_STYLE改名为HIDDEN_STYLE吧
const gesture = useMemo(() => { | ||
return Gesture.Pan() | ||
.onTouchesDown((e: GestureTouchEvent) => { | ||
'worklet' |
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.
直接回调里应该不用写worklet
} | ||
}) | ||
.withRef(movableGestureRef) | ||
}, [disabled, direction, inertia, outOfBounds, handleTriggerMove, handleTriggerStart, handleTriggerEnd]) |
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.
这里面有些依赖是必定变化的,会导致memo失效,不用重新执行的逻辑可以考虑都放在一个大memo中
<Animated.View | ||
ref={nodeRef} | ||
onLayout={onLayout} | ||
style={[styles.container, innerStyle, animatedStyles, layoutStyle]} |
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.
defaultStyle可以在早期合入
useNodesRef(props, ref, nodeRef, { | ||
defaultStyle: styles.container | ||
defaultStyle: styles.container, |
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.
这个地方defaultStyle不用传递了,把normalStyle作为style传递进去就可以,内部的getComputedStyle也直接使用这里传递的normalStyle,而不需要读取props.style了
} | ||
} | ||
if (simultaneousHandlers && simultaneousHandlers.length) { | ||
gesture.simultaneousWithExternalGesture(...simultaneousHandlers) |
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.
这里得考虑清空之前的注册,否则会无限累加
if (gesture?.nodeRefs) { | ||
return gesture.nodeRefs | ||
.map((item: { getNodeInstance: () => any }) => item.getNodeInstance()?.instance?.gestureRef || {}) | ||
.filter(Boolean) |
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.
这个是啥意思啊
} | ||
|
||
export function flatGesture (gestures?: Array<GestureHandler>) { | ||
return gestures && gestures.flatMap((gesture: GestureHandler) => { |
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.
这个flatMap在哪定义的?
No description provided.