嘿伙计们,我刚刚开始学习 React Native context api 我想知道我如何像全局状态一样全局实现它,并且在导航到另一个屏幕后它也不起作用,为什么我们在提供程序中包含类名<ProfileScreen screen= {this.state.contextData}/>我们可以全局执行.. 这是我的代码
global.cart=1
const Context = React.createContext(global.cart)
class HomeScreen extends Component<Props> {
constructor(props){
super(props);
this.state={
contextData:5
}
}
Incrementhome=()=>{
this.setState({contextData:global.cart})
global.cart++
}
Decrementhome=()=>{
this.setState({contextData:global.cart})
global.cart--
}
render() {
return (
<View>
<Context.Provider value={this.state.contextData}>
<Button title="Incrementhome"
onPress={this.Incrementhome}/>
<Button title="decrementhome"
onPress={this.Decrementhome}/>
<ProfileScreen screen= {this.state.contextData}/>
</Context.Provider>
<Button title='sd' onPress={()=>{this.props.navigation.navigate('Profile')}}/>
</View>
)
}
}
Run Code Online (Sandbox Code Playgroud)
可以显示我的数据的类配置文件屏幕
class ProfileScreen extends Component<Props> {
render() {
return (
<View style={{}}>
<Context.Consumer>
{data=> <Text style={{fontSize:50}}>{data}</Text>}
</Context.Consumer>
</View>
);
}
} …Run Code Online (Sandbox Code Playgroud) 使用 react-navigations - createBottomTabNavigator,我试图将图标向下推一点,但它被切断了,我不确定为什么。
有没有办法解决这个问题?或者如果你能指导我获得一些关于这方面的信息。
图标样式如下:
<Icon
name="heart"
color={tintColor}
size={28}
style={{ marginTop: '20' }}
/>
Run Code Online (Sandbox Code Playgroud)
这是标签栏选项:
tabBarOptions: {
showLabel: false,
activeTintColor: '#e91e63',
indicatorStyle: {
height: 100
},
style: {
position: 'absolute',
backgroundColor: 'transparent',
height: 50,
width: DEVICE_WIDTH * 0.94,
borderTopColor: 'transparent',
borderBottomLeftRadius: 33,
borderBottomRightRadius: 33,
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
bottom: 0,
margin: 10,
shadowColor: '#000000',
shadowOffset: {
width: 0,
height: 0.3
},
shadowRadius: 5,
shadowOpacity: 0.1
},
tabStyle: {}
}
Run Code Online (Sandbox Code Playgroud)
提前谢谢了
react-native react-native-android react-native-ios react-navigation
当我运行时出现react-native link此错误
链接时出了点问题。
错误:ENOENT:没有那个文件或目录,打开'D:\ ...{MY_APP_NAME}\android \app\src\main\java\com{MY_APP_NAME}\android\MainApplication.java'
尝试在 android 上加载应用程序以进行本机反应时遇到此问题(它适用于 ios )
似乎导入'react-native'不起作用。我跑了npm install
这是导致错误的文件:
import { Text } from 'react-native'
import DebugConfig from './DebugConfig'
import AppConfig from './AppConfig'
// Allow/disallow font-scaling in app
Text.defaultProps.allowFontScaling = AppConfig.allowTextFontScaling
if (__DEV__) {
// If ReactNative's yellow box warnings are too much, it is possible to turn
// it off, but the healthier approach is to fix the warnings. =)
console.disableYellowBox = !DebugConfig.yellowBox
}
Run Code Online (Sandbox Code Playgroud) 我在 react-native-android 中创建了一个 2 列的 FLatlist
1 | 2
------------
3 | 4
Run Code Online (Sandbox Code Playgroud)
我要这个
2 | 1
4 | 3
Run Code Online (Sandbox Code Playgroud)
我尝试这些:
<View style={{flex:1,flexDirection:'row-reverse'}}>
<FlatList
style={{flex:1,flexDirection:'row-reverse'}}
Run Code Online (Sandbox Code Playgroud)
在渲染项目我使用flexDirection:'row-reverse'过
但没有成功!
react-native react-native-android react-native-flexbox react-native-flatlist
当我运行react-native run-android它说:
FAILURE:构建失败,出现异常。
* What went wrong:
Could not update time stamp for /home/userName/Desktop/hello-world/android/.gradle/4.10.2/gc.properties
运行后--stacktrace,显示:
* Exception is:
org.gradle.api.UncheckedIOException: Could not update time stamp for /home/userName/Desktop/hello-world/android/.gradle/4.10.2/gc.properties.
这可能是什么原因?我搜索了很多,但未能找到解决方案。
我正在为我的移动应用程序使用 react-navigation,我有 2 条路线 - Home 和 Favoriti,其中 Home 是初始路线。这两个组件都有 componentDidMount。每当我从 Home 导航到 Favoriti 时,Favoriti 组件都会挂载,但是当我导航回 Home 时,它的 componentDidMount 不会执行。它仅在我第一次打开应用程序时执行,但我每次导航到它时都需要挂载它。
import { createStackNavigator, createAppContainer} from 'react-navigation';
import Home from './views/Home';
import Favoriti from './views/Favoriti';
const MainNavigator = createStackNavigator({
FavoritiRT: Favoriti,
HomeRT: Home
},
{
initialRouteName: "HomeRT"
}
);
const MyRoutes = createAppContainer(MainNavigator);
export default MyRoutes;
Run Code Online (Sandbox Code Playgroud)
没有错误显示,只是初始路由的 componentDidMount 不会在我每次导航到它时执行,但在其他路由中它会执行。
javascript navigation android-lifecycle react-native react-native-android
我想将 Firebase Crashlytics 添加到我的 React 原生项目中。我在网上查看了一些链接,建议将 Crashlytics 与 Fabric 结合使用,
当我查看 Fabric 时,有人提到它只在 2020 年之前可用,并建议使用 Firebase Crashlytics。我有点困惑。
任何人都可以建议任何链接/指南来在我的 React 本机项目中实现 Firebase Crashlytics。
谢谢
我必须让用户在他按下按钮时下载 pdf 文件,我发现我必须使用 rn-fetch-blob 而不是 react-native-fetch-blob。在文档中有这个代码:
const { config, fs } = RNFetchBlob
let DownloadDir = fs.dirs.DownloadDir // this is the Downloads directory.
let options = {
fileCache: true,
addAndroidDownloads : {
useDownloadManager : true, //uses the device's native download manager.
notification : true,
title : "Notification Title", // Title of download notification.
path: DownloadDir + "/me_"+ '.' + extension, // this is the path where your download file will be in
description : 'Downloading file.'
}
}
config(options)
.fetch('GET',"https://whatever_url_u …Run Code Online (Sandbox Code Playgroud) 我想将对象添加到我的状态,我已经搜索解决它,但所有这些都不起作用
this.state = {
value : {name:'test'}
};
Run Code Online (Sandbox Code Playgroud)
我想在 this.state.value 中添加一个对象 {coordinate:'0,0'}
我试过这个,但我得到了错误:传播不可迭代实例的尝试无效
let floors = [...this.state.value];
floors.push({ coordinate: '0,0'});
this.setState({ value:floors });
Run Code Online (Sandbox Code Playgroud)
我试过这个,但我得到了错误:传播不可迭代实例的尝试无效
this.setState({
value:[...this.state.value, {coordinate: '0,0'}]
});
Run Code Online (Sandbox Code Playgroud)
我试过这个,但我得到了错误:_this2.state.value.concat is not a function
this.setState( {
value: this.state.value.concat({koordinat:coor})
});
Run Code Online (Sandbox Code Playgroud)
请帮我解决它
react-native ×8
reactjs ×3
android ×2
crashlytics ×1
firebase ×1
gradle ×1
javascript ×1
navigation ×1