HarmonyOS RN ScrollView scrollTo Crash

在rn里使用ScrollView组件,如下使用方式:

<ScrollView
ref={flatListL1}
style={styles.firstFlatList}
showsVerticalScrollIndicator={false}
onLayout={() => {
  if (!hasL1OnLayouted.current) {
  hasL1OnLayouted.current = true
  const idx = Math.max(allData.data.l1.findIndex((item) => item.id === allData.selected.item1?.id), 0)
  console.log(idx, flatListL1?.current)
  flatListL1?.current.scrollTo({ x: 0, y: pxToDp(96) * idx, animated: false })
}
}}>
</ScrollView>

当调用flatListL1?.current.scrollTo时,稳定crash,从日志看应该是C++ 空指针了,日志如下:

Reason:Signal:SIGSEGV(SEGV_MAPERR)@0x0000000000000020  probably caused by NULL pointer dereference
Fault thread info:
  Tid:60760, Name:com.yupao.zhho
#00 pc 00000000000fea14 /data/storage/el1/bundle/libs/arm64/libreact_render_core.so(std::__n1::weak_ptr<facebook::react::EventDispatcher const>::lock() const+68)(ea6964530684c90458078758b18e2c90965152df)
#01 pc 00000000000fe684 /data/storage/el1/bundle/libs/arm64/libreact_render_core.so(facebook::react::EventEmitter::dispatchUniqueEvent(std::__n1::basic_string<char, std::__n1::char_traits<char>, std::__n1::allocator<char>>, std::__n1::function<facebook::jsi::Value (facebook::jsi::Runtime&)> const&) const+84)(ea6964530684c90458078758b18e2c90965152df)
#02 pc 00000000000bc328 /data/storage/el1/bundle/libs/arm64/librrc_scrollview.so(facebook::react::ScrollViewEventEmitter::onScroll(facebook::react::ScrollViewMetrics const&) const+108)(9b2aa5e6325ef98f8d2153472cc30f7b0f0eaafa)
#03 pc 00000000008a3d1c /data/storage/el1/bundle/libs/arm64/librnoh.so(rnoh::ScrollViewComponentInstance::onScroll()+1012)(97cd6d0faea82ca9df548a9e79887a33076b515d)
#04 pc 0000000000847a54 /data/storage/el1/bundle/libs/arm64/librnoh.so(rnoh::ScrollNode::onNodeEvent(ArkUI_NodeEventType, ArkUI_NumberValue (&) [12])+100)(97cd6d0faea82ca9df548a9e79887a33076b515d)
#05 pc 0000000000838ce4 /data/storage/el1/bundle/libs/arm64/librnoh.so(rnoh::ArkUINodeRegistry::receiveEvent(ArkUI_NodeEvent*)+956)(97cd6d0faea82ca9df548a9e79887a33076b515d)
#06 pc 0000000000838eb4 /data/storage/el1/bundle/libs/arm64/librnoh.so(97cd6d0faea82ca9df548a9e79887a33076b515d)
#07 pc 0000000000838e88 /data/storage/el1/bundle/libs/arm64/librnoh.so(97cd6d0faea82ca9df548a9e79887a33076b515d)

请帮忙分析是什么原因?

HarmonyOS
13h前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

参考demo:

import React, { useRef } from 'react';
import {
  StyleSheet,
  Text,
  SafeAreaView,
  ScrollView,
  StatusBar,
} from 'react-native';

const App = () => {
  const flatListL1 = useRef(null)
  const A=()=>{
    if(flatListL1.current){
      flatListL1.current.scrollTo({ x: 0, y: 96, animated: false })
      console.info('触发滚动')
    }
  }
  return (
    <SafeAreaView>
      <ScrollView
  style={styles.scrollView}
  ref={flatListL1}
  onLayout={
    ()=>{
    A()
  }
}
  >
  <Text style={styles.text}>
  xxxxx
  </Text>
  </ScrollView>
  </SafeAreaView>
);
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    paddingTop: StatusBar.currentHeight,
  },
  scrollView: {
    backgroundColor: 'pink',
    marginHorizontal: 20,
  },
  text: {
    fontSize: 42,
  },
});

export default App;
分享
微博
QQ
微信
回复
9h前
相关问题
HarmonyOS RN相关界面crash
74浏览 • 1回复 待解决
ScrollView嵌套ListContainer
7043浏览 • 5回复 待解决
ScrollView里面套着ListContainer
6017浏览 • 9回复 待解决
HarmonyOS 有没有类似scrollview的组件
457浏览 • 1回复 待解决
HarmonyOS taskpool使用crash
1586浏览 • 2回复 待解决
如何实现crash堆栈抓取、crash回调
2040浏览 • 1回复 待解决
HarmonyOS 关于crash问题
588浏览 • 1回复 待解决
ScrollView默认从底端开始,怎么破?
5216浏览 • 1回复 待解决
请问ScrollView怎么显示滚动条?
5600浏览 • 1回复 待解决
HarmonyOS FrameNode手势检测crash
17浏览 • 1回复 待解决
鸿蒙中ScrollView如何禁掉滚动事件
7372浏览 • 2回复 待解决
HarmonyOS crash异常无法上报问题
197浏览 • 1回复 待解决
HarmonyOSRN导出对象对齐原版RN
5浏览 • 0回复 待解决
HarmonyOS 遇到JSON.stringify crash
505浏览 • 1回复 待解决
HarmonyOS 使用全局 @Builder 应用 crash
2浏览 • 1回复 待解决
HarmonyOS 线上crash 等性能监控
186浏览 • 1回复 待解决