Unsupported top level event type top scroll dispatched navigatorios năm 2024

you should re-consider if params is an appropriate place to have this data if you don't want in the url. that you think that the url contains irrelevant data is a sign that the data doesn't belong in the navigation state.

if you visit a screen directly from a url, it should render the same as when you navigated to it porgrammatically. if you're passing something in params, it means that that information is needed for the screen to render correctly, and if you remove it from the url, then that information is lost. consider that it's possible to open the page directly from a url, either on web or with a deep link. if the required data isn't available, then it's not going to work.

in your case, seems like you're passing a full user object (maybe not, hard to say without code). ideally, this object should be in your global store instead of params, and you should only pass the user id in params. then you should gran the full object from your global store using that id, or trigger a data fetch if the objet isn't fetched yet (if needed).

you didn't specify the version of react navigation in your question. in v5, you can customize how your params are stringified to urls, and how they are parsed back using the stringify and parse options:

const linking = {
  screens: {
    profile: {
      path: 'user/:id',
      parse: {
        id: (id) => id.replace(/^@/, '')
      },
      stringify: {
        id: (id) => `@{id}`,
      },
    },
  },
};

this should help you with making urls look prettier, and handle cases where params are not simple strings. however you can't omit params from the url altogether since they are necessary data for the screen to render.

我有一个简单的两页设置使用NavigatorIOS为一个iOS应用程序使用React。在我的应用程序加载之后,我可以单击第二个页面,但是当我单击“后退”(左上角)时,我会得到以下错误:

Unsupported top level event type "topScroll" dispatched
extractEvents
ReactNativeFiber-dev.js:3519:22
extractEvents
ReactNativeFiber-dev.js:3298:71
handleTopLevel
ReactNativeFiber-dev.js:3539:64

ReactNativeFiber-dev.js:3560:55
batchedUpdates
ReactNativeFiber-dev.js:2754:26
batchedUpdatesWithControlledComponents
ReactNativeFiber-dev.js:209:34
_receiveRootNodeIDEvent
ReactNativeFiber-dev.js:3559:50
receiveEvent
ReactNativeFiber-dev.js:3564:60
__callFunction
MessageQueue.js:302:47

MessageQueue.js:116:26
__guard
MessageQueue.js:265:6
callFunctionReturnFlushedQueue
MessageQueue.js:115:17

在模拟器和设备上运行时(来自xcode)会发生错误。

这是我的应用程序的代码。我确信我没有正确地初始化一些东西,我只是不知道那是什么:

'use strict';
import React, { Component } from 'react';
import {
  StyleSheet,
  Button,
  Text,
  View,
  NavigatorIOS
} from 'react-native';
const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  scene: {
    padding: 10,
    paddingTop: 74,
    flex: 1,
  }
})
class PageFeedItem extends Component {
  render() {
    return(
      
        Some text
      
    );
  }
}
class PageFeed extends Component {
  constructor(props, context) {
    super(props, context);
    this.onShowFeedItem = this.onShowFeedItem.bind(this);
  }
  onShowFeedItem() {
    this.props.navigator.push({
      component: PageFeedItem,
      title: "Feed Item",
      passProps: {}
    });
  }
  render() {
    return(
      
        Feeds
        

更新

自从提出这个问题以来,我注意到了两件事:

1)当错误发生时,按下ESC,应用程序似乎没有问题地继续运行。

2)向第二个页面添加一个Button,并添加一个处理程序来执行this.props.navigator.pop();,这似乎很好,即在错误中不能解决问题。

回答 4

Stack Overflow用户

发布于 2017-11-07 11:29:31

我也面临着同样的问题,然后将react原生版本从0.50更改为0.49。*一切正常。这是最新版本的react本机中已知的错误。

Stack Overflow用户

发布于 2018-05-29 14:00:21

用ScrollView包装屏幕。

render() {
    return (
      
      
        Test screen
      
      
     );
  }
}

Stack Overflow用户

发布于 2018-04-24 03:03:22

尝试在PageFeed类中添加以下代码:

static propTypes = {
    title: PropTypes.string.isRequired,
    navigator: PropTypes.object.isRequired,
}

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持

原文链接:

https://stackoverflow.com/questions/47118487

复制