- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 react 原生新手。现在我需要在两个屏幕上实现一个功能。当我单击“addActivity”场景中的底部时,它将返回“homeScene”,即“addActivity”的前一个场景,并显示“addActivity”场景中的数据。
我尝试通过 map 将数据存储在“addActivity”场景中:
export const m = new Map();
并导入homeScene场景中的 map
import { m } from './addActivity';
我不确定这种方式是否好。我看到react-native-navigation有一些函数可以传递参数,但我不知道如何使用它们。现在最大的问题是当我从“addActivity”场景中使用 goBack() 时如何刷新“homeScene”场景。有两个场景的代码
homeScene.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
TextInput,
View,
TouchableOpacity,
Dimensions
} from 'react-native';
import { m } from './addActivity';
export default class LeftSideMenu extends Component {
constructor(props) {
super(props);
this.state = {
isOpen: false,
}
add = () => {
const { navigate } = this.props.navigation;
navigate('Add');
}
render() {
return (
<View style={styles.container}>
//I want to show the data here
<Text
style={styles.btText2}>{m.get("title")}</Text>
//This is the bottom to jump to "addActivity" scene
<TouchableOpacity
onPress={this.add}
style={styles.Addbutton}>
<Text
style={styles.btText2}>+</Text>
</TouchableOpacity>
</View>
);
}
}
addActivity.js
import React, { Component } from 'react';
import { View, ScrollView, Dimensions, StyleSheet, Text, Button, TouchableOpacity, Alert } from 'react-native';
import { NavigationPage, ListRow, Input, Select, Label } from 'teaset';
let { height, width } = Dimensions.get('window');
//initial the map
export const m = new Map();
export default class InputExample extends Component {
constructor(props) {
super(props);
this.state = {
length: 0,
title: '',
isVisible: false,
};
Object.assign(this.state, {
valueTitle: null,
});
}
//Return to homeScene
homeScene = () => {
m.set("title", this.valueTitle);
const { goBack } = this.props.navigation;
Alert.alert("Add succeed","return to Homepage",[{text: 'confirm', onPress: () => { goBack(); }}])
}
render() {
return (
<ScrollView style={{ flex: 1 }}>
<ListRow title='Title *' detail={
<Input
style={{ width: 200 }}
size='md'
value={this.state.valueMD}
placeholder=''
onChangeText={text => this.setState({ valueTitle: text })}
/>
} topSeparator='full' />
<TouchableOpacity
onPress={this.homeScene}
style={styles.button}>
<Text
style={styles.btText}>Confirm</Text>
</TouchableOpacity>
</ScrollView>
);
}
}
我希望当我对 homeScene 使用 goBack() 时,场景可以刷新,并且来自 addActivity 场景的数据可以打印在 homeScene 上
最佳答案
为了刷新返回的上一个屏幕,您可以在要在从某个屏幕返回时更新组件状态的屏幕中使用此代码
componentDidMount()
this.getMoviesFromApiAsync()
this.props.navigation.addListener('willFocus',this._handleStateChange);
}
_handleStateChange = state => {
alert('Refreshed successfully!')
this.getMoviesFromApiAsync()
};
其中 getMoviesFromApiAsync()
是包含 API 调用代码的方法。
或您可以使用 Redux 来实现相同的目的。
关于javascript - 当我 goBack() 时如何刷新上一个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55884168/
在我的 React Native 应用程序中,我有三个屏幕,如 A 和 B。我使用 react-navigation 版本 5 从一个屏幕导航到另一个屏幕。 当我从 A 移动到 B 并在 B 中输入一
场景是我有一个日历页面,该页面显示一个月中的所有日子,每天都有一个添加按钮: 当我单击添加按钮时,它会将我带到另一个页面,如果用户点击硬件后退按钮,我希望应用程序返回日历页面,但我希望页面滚动到用户最
我正在创建一个应用程序,我登录/注销有一个主页、关于、个人资料等。它也使用 react 路由器,但是当我登录时,我希望应用程序转换到它所在的最后一个路由,它有时会起作用,例如,如果我访问 about,
我如何错误检查Chrome浏览器是否有前一页?如果 Chrome 实例刚刚启动,并且没有上一页要使用命令page进入,我有一个冻结的按钮。 最佳答案 这是一个错误,不是预期的行为。您应该考虑将其报告为
我是 react 原生新手。现在我需要在两个屏幕上实现一个功能。当我单击“addActivity”场景中的底部时,它将返回“homeScene”,即“addActivity”的前一个场景,并显示“ad
我一直在阅读许多类似的问题和答案,但仍然不太明白这里出了什么问题。 我正在尝试创建一个按钮以返回上一个 View ,但我不断收到标题中提到的错误。有人可以告诉我我做错了什么吗? UIImage *i
我从一个不是tab的页面跳转到tab页。 在tab页,点击item后想返回。我使用 $ionicHistory.goBack() 返回。 我发现一个奇怪的情况,第一次$ionicHistory.goB
我正在尝试在按下 goBack 后重新渲染组件。通过使用 goBack 我可以返回页面,但该页面不会刷新。我该如何解决?goBack 之后我必须调用一些 api,现在在 back non of the
我的应用程序有一个要求,我需要在 webview 中呈现多个网页并提供 goback() 方法。 但不幸的是 goback() 方法在我们加载不退出的 url(来自多个页面的 url 之一)的情况下不
我正在开发一个使用 WKWebView 和自定义导航按钮的 iOS 应用程序。我们发现点击某些链接需要使用我们的后退按钮两次,因为第一次调用似乎只是重新加载当前页面。这不会发生在移动版 Safari
我正在使用reactjs构建一个应用程序,在某些时候我有一个SearchForm,然后我单击其中一个项目,在该 View 中我有一个后退按钮。 我想要的是用以前的数据填充搜索表单。我已经通过 java
我在页面中有产品列表。这个产品列表只会显示 5 个。单击“显示额外”按钮后,它将显示剩余的产品。 好的,在我点击“显示额外”按钮后,它会显示接下来的 5 个产品。现在共有 8 个产品。在剩下的 5 个
这是主要 Activity 的xml代码..
我创建了一个简单的应用程序来重现该问题。我有一个带有相关链接的 html 文件(带有 # 符号)。我正在将文件加载到 Android 的 WebView 中。但我只能通过链接访问一次。返回后,当我点击
我已经设置了一个 StackNavigator,它会触发一个 redux 操作来获取 componentDidMount 上的数据,在导航到另一个屏幕并返回到上一个屏幕后,componentDidMo
我有两个屏幕。每个屏幕包含三个子类。是的,我正在使用每个屏幕的选项卡。在我的第一个屏幕上说。 主屏幕 有 -> ScreenA、ScreenB、ScreenC。我的 DetailScreen 有 ->
我想在从另一个页面导航回来时向下滚动到 GridView 的底部。更具体地说,Frame.GoBack(NavigationTransitionInfo) 结束时,滚动将可见。是否有回调或某种方式在转
我面临返回上一页的问题,如果有人帮助我,将非常感谢。 这是我的 Controller 登录操作 public function actionLogin() { $this->l
关于TWebBrowser方法,我在GoBack上遇到问题。以下是显示问题的导航历史记录: [1] htt#://www.google.com/ [2] htt#://news.google.com/
我创建了一些动画,我想用它们在我的应用程序中的路线之间导航。我在某些页面上有一个可见的后退按钮,允许用户弹出导航堆栈以访问最近的页面。我想要两种不同的动画,一种用于在堆栈中更深入地导航,另一种用于弹回
我是一名优秀的程序员,十分优秀!