我正在使用反应导航。我想在屏幕的标题上方显示抽屉。当前,当我打开抽屉时,标题没有隐藏在抽屉下方。
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { createStackNavigator, createDrawerNavigator } from 'react-navigation';
import CategoryScreen from './CategoryScreen';
import ProductsScreen from './ProductsScreen';
import CartScreen from './CartScreen';
const drawerScreens = createDrawerNavigator ({
Category: CategoryScreen,
Products: ProductsScreen,
},{
initialRouteName: 'Category'
}
)
export default AppStack = createStackNavigator(
{
drawer: {
screen: drawerScreens,
navigationOptions: ({ navigation }) => ({
header: <View style={styles.container}><Text>Header</Text></View>
}),
},
cart: {screen: CartScreen}
},
{
initialRouteName: 'drawer',
}
);
const styles = StyleSheet.create({ …Run Code Online (Sandbox Code Playgroud)我正在使用 react-native-firebase 进行远程推送通知。当应用程序打开或在后台时,我能够收到通知。但是,当我终止应用程序并将其从内存中删除时,一旦我从 Firestore 应用程序发送消息,手机就会崩溃。我遵循了完整的文档并按照文档进行了操作。应用程序崩溃的原因是什么,我该如何解决?
我的 App.js
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import firebase from 'react-native-firebase';
import type { Notification, NotificationOpen } from 'react-native-firebase';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
export default class App extends Component {
async componentDidMount() {
const notificationOpen: NotificationOpen = …Run Code Online (Sandbox Code Playgroud)我在 React Native 应用程序中使用 React-navigation v2 创建了一些选项卡。我创建了 componentDidMount 函数,其中调用 willFocus。第一次运行应用程序并且第一次选择我想要的选项卡时,willFocus 不会执行。但是,当我转到不同的选项卡并返回该选项卡时,现在 willFocus 会执行。willFocus第一次不执行而第二次运行正常的原因是什么?
所需的选项卡 componentDidMount 函数
componentDidMount(){
const {navigation} = this.props;
navigation.addListener ('willFocus', async () =>{
console.log("willFocus runs"
});
}Run Code Online (Sandbox Code Playgroud)
选项卡导航器与其他导航器嵌套,但我只显示下面的选项卡导航器
TabNav: createBottomTabNavigator(
{
TAB1: Screen1,
TAB2: Screen2,
TAB3: Screen3,
TAB4: Screen4,
TAB5: Screen5,
// Map: MapScreen
},
{
initialRouteName: 'Bar',
transitionConfig: NavigationConfig,
navigationOptions: ({navigation})=>({
tabBarIcon: ({focused, tintColor})=>{
const { routeName } = navigation.state;
let iconName, iconSize;
switch(routeName) {
case "TAB1":
iconName = `icon1`;
break;
case "TAB2":
iconName = `icon2`; …Run Code Online (Sandbox Code Playgroud)我需要从静态导航选项调用操作,但无法通过 this.props 访问我的操作。如何调用这个动作?我在控制台中收到错误“无法读取未定义的属性‘注销’”。
static navigationOptions = ({navigation}) =>( {
title: 'Home',
header: <Header headerTitle={navigation.state.routeName} logoutButtonPress={() => {
this.props.logout(); // this action is not working
NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: "Welcome" })]
})
navigation.navigate('Welcome');
}
}
/>,
});Run Code Online (Sandbox Code Playgroud)
我在expressjs应用程序中使用express-validator 5.2.0。我在表单数据上实现了验证。但是它不会捕获错误,而是提供空错误对象。验证运行时,当我提交空白表格时,它显示“无错误”。它应遵循错误路径并应显示错误。
var express = require('express');
var router = express.Router();
const { check, validationResult } = require('express-validator/check');
router.post('/register', [
check('firstName', 'First Name is required').isEmpty(),
check('lastName', 'Last Name is required').isEmpty(),
check('username', 'User Name is required').isEmpty(),
check('password', 'Password is required').isEmpty()
], (req, res, next)=>{
let errors = validationResult(req);
if (!errors.isEmpty()) {
console.log(errors.mapped());
console.log("errors")
return res.render('auth/register', { errors: errors.mapped() })
}else{
console.log('no errors')
return res.render('auth/login');
}Run Code Online (Sandbox Code Playgroud)
我在反应原生中使用API获取数据.在控制台中获取数据时,它成功获取数据.但是在使用下面的代码时,相册数组显示未定义.
state = { albums: [] };
componentWillMount() {
//fetch('https://ws.audioscrobbler.com/2.0/?method=chart.gettoptracks&api_key=881262b246e1d3f2abda8771b1a25fe3&format=json')
fetch('https://rallycoding.herokuapp.com/api/music_albums')
.then(response => this.setState({ albums: response.data }));
}Run Code Online (Sandbox Code Playgroud)
我正在获得这样的控制台日志
{albums:Array(0)}
{albums:undefined}
为什么这是未定义的?