gpt4 book ai didi

javascript - 在 NavigatorIOS 中导航返回 native

转载 作者:行者123 更新时间:2023-11-30 11:14:44 25 4
gpt4 key购买 nike

我正在我的 React Native 项目中测试 NavigatorIOS。问题是当我按下按钮从一个组件导航到另一个组件时没有问题但是当我尝试使用 NavigatorIOS 生成的标题栏中的按钮返回时,我收到此错误:“不支持的顶级事件”topScroll“已 dispatch ”。

我使用 react-native-cli = 2.0.1 和 react-native = 0.56.0

注意:当我在支持组件中按下“返回”按钮时一切正常。

这是我的代码:

应用组件:

import React, { Component } from "react";
import { View, NavigatorIOS } from "react-native";

import { NavigationApp } from "./src/components/index.js";

export default class App extends Component {
render() {
return (
<NavigatorIOS
style={{ flex: 1 }}
initialRoute={{
title: "Navigation app",
component: NavigationApp
}}
/>
);
}
}

NavigationApp 组件:

import React, { Component } from "react";
import { Text, View, Button, NavigatorIOS } from "react-native";
import { Support } from "./index.js";

class NavigationApp extends Component {
navigateToSupport = () => {
this.props.navigator.push({
title: "Support",
component: Support
});
};

render() {
const { containerStyle } = styles;
return (
<View style={containerStyle}>
<Button
title="Go to support page"
onPress={this.navigateToSupport}
/>
</View>
);
}
}

const styles = {
containerStyle: {
flex: 1,
justifyContent: "center",
alignItems: "center"
}
};

export { NavigationApp };

支持组件:

import React, { Component } from "react";
import { View, Text, Button } from "react-native";

class Support extends Component {
backAction = () => {
this.props.navigator.pop();
};

render() {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems:"center" }}>
<Text>You are in support page</Text>
<Button title="Go back" onPress={this.backAction} />
</View>
);
}
}

export { Support };

最佳答案

解决方法是将您的初始组件包装在ScrollView

<ScrollView>
// ... Initial Component code
</ScrollView>

这是一个悬而未决的问题,您可以按照线索here

关于javascript - 在 NavigatorIOS 中导航返回 native ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52071515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com