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

RN 0.61.5 ScrollView 调用 scrollTo 方法报错: MJScrollViewManager.zoomToRect was called with 4 arguments but expects 3 arguments. #53

Open
bigggge opened this issue Jan 20, 2020 · 8 comments

Comments

@bigggge
Copy link

bigggge commented Jan 20, 2020

RN 0.61.5 使用 MJScrollView 时,调用 scrollTo scrollToOffset 等方法时报错
RN 0.59.10 使用 MJScrollView 正常
RN 0.61.5 使用自带的 ScrollView 正常

"MJScrollViewManager.zoomToRect was called with 4 arguments but expects 3 arguments. If you haven't changed this method yourself, this usually means that your versions of the native code and JavaScript code are out of sync. Updating both should make this error go away."

通过修改 react-native/Libraries/Components/ScrollResponder.js

    UIManager.dispatchViewManagerCommand(
      nullthrows(this.scrollResponderGetScrollableNode()),
      UIManager.getViewManagerConfig('RCTScrollView').Commands.scrollTo,
      [x || 0, y || 0, animated !== false],
    );

发现方法调用错乱
调 scrollTo 会执行 zoomToRect
调 scrollToEnd 会执行 flashScrollIndicators
调 flashScrollIndicators 会执行 scrollToEnd

@mike1023
Copy link

@bigggge 请问你引入库运行时正常?我直接报’ListView has been removed‘

@bigggge
Copy link
Author

bigggge commented Feb 10, 2020

@bigggge 请问你引入库运行时正常?我直接报’ListView has been removed‘

我是把源码 copy 下来的,然后删了 ListView 相关的代码

@FrankyLee-dev
Copy link

RN 0.61.4 调用scrollToOffset有同样的问题。

@bigggge
Copy link
Author

bigggge commented Mar 3, 2020

@frankyLHJ

我修改了 RCTMJScrollViewManager.m , 就可以了,但不太清楚原理

加上

RCT_EXPORT_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsVerticalScrollIndicator, BOOL)
RCT_EXPORT_VIEW_PROPERTY(scrollEventThrottle, NSTimeInterval)
RCT_EXPORT_VIEW_PROPERTY(zoomScale, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
RCT_EXPORT_VIEW_PROPERTY(scrollIndicatorInsets, UIEdgeInsets)
RCT_EXPORT_VIEW_PROPERTY(scrollToOverflowEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(snapToInterval, int)
RCT_EXPORT_VIEW_PROPERTY(disableIntervalMomentum, BOOL)
RCT_EXPORT_VIEW_PROPERTY(snapToOffsets, NSArray<NSNumber *>)
RCT_EXPORT_VIEW_PROPERTY(snapToStart, BOOL)
RCT_EXPORT_VIEW_PROPERTY(snapToEnd, BOOL)
RCT_EXPORT_VIEW_PROPERTY(snapToAlignment, NSString)
RCT_REMAP_VIEW_PROPERTY(contentOffset, scrollView.contentOffset, CGPoint)
RCT_EXPORT_VIEW_PROPERTY(onScrollBeginDrag, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onScrollToTop, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onScrollEndDrag, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onMomentumScrollBegin, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onMomentumScrollEnd, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(DEPRECATED_sendUpdatedChildFrames, BOOL)

@FrankyLee-dev
Copy link

@bigggge 按你的添加了,但是还是会报错。
image
我就是想实现一个滑到顶部的功能
在flatlist上添加ref={flatlist => (this._flatlist = flatlist)},
然后this._flatlist && this._flatlist.scrollToOffset({animated: true, viewPosition: 0, index: 0});

@wenkangzhou
Copy link

我按@bigggge的方法可行,其实就是把RCTScrollView里的copy过来,比对发现新增了scrollToOverflowEnabled、disableIntervalMomentum这两个,之前debug发现生成MJScrollViewManager方法的数组顺序和代码上是不一致的,自然和ScrollView也不一致,调scrollTo最终调到的其实是scrollToEnd,估计就是少了这两个属性的定义,所以整个顺序不对了,至于深层的原理也搞不明白,总之RCTScrollView有改动,最好也同步改动

@FrankyLee-dev
Copy link

@wenkangzhou 能看下你是怎么改的嘛?谢谢

@wenkangzhou
Copy link

@wenkangzhou 能看下你是怎么改的嘛?谢谢

我和@bigggge改法一样啊,他已经贴出来了

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

No branches or pull requests

4 participants