React Native和本机基本编辑数据页面

时间:2019-07-01 21:15:23

标签: react-native native-base

我正在尝试创建一个页面,以便在其中编辑“承租人”数据。

这是我的页面:

import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import {
  Container, Header, Content, Card,
  CardItem, Text, Icon, Right,
  Left, Body, Title, Button }
from 'native-base';
import { Avatar } from 'react-native-elements';
import NavigationService from '../NavigationService';

class TenantDetails extends Component {
  render() {
    const { navigation } = this.props;
    return (
      <Container>
        <Header>
          <Left>
            <Button
              transparent
              onPress={() => NavigationService.navigate('Tenants')}
            >
              <Icon name='arrow-back' />
            </Button>
          </Left>
          <Body>
            <Title>My Name</Title>
          </Body>
          <Right />
        </Header>
        <Content>
          <View style={styles.userRow}>
            <View style={styles.userImage}>
              <Avatar
                rounded
                size="large"
                source={{
                  uri: 'https://myirent.com/rent/appImg/person-icon.png',
                }}
              />
            </View>
            <View>
              <Text style={{ fontSize: 16 }}>Jonh Test</Text>
              <Text
                style={{
                  color: 'gray',
                  fontSize: 16,
                }}
              >
                joinh@gmail.com{'\n'}xxx-xxx-xxxx
              </Text>
            </View>
          </View>
          <Card>
            <View style={styles.containerTextHeader}>
              <Text style={styles.infoTextHeader}>Tenant Details</Text>
            </View>
            <CardItem>
              <Icon active name="logo-googleplus" />
              <Text>First Name</Text>
              <Right>
                <Icon name="arrow-forward" />
              </Right>
            </CardItem>
          </Card>
        </Content>
      </Container>
    );
  }
}

const styles = StyleSheet.create({
  scroll: {
    backgroundColor: 'white',
  },
  userRow: {
    alignItems: 'center',
    flexDirection: 'row',
    paddingBottom: 8,
    paddingLeft: 15,
    paddingRight: 15,
    paddingTop: 6,
  },
  userImage: {
    marginRight: 12,
  },
  listItemContainer: {
    height: 55,
    borderWidth: 0.5,
    borderColor: '#ECECEC',
  },
  containerTextHeader: {
    paddingTop: 20,
    paddingBottom: 12,
    backgroundColor: '#F4F5F4',
  },
  infoTextHeader: {
    fontSize: 16,
    marginLeft: 20,
    color: 'gray',
    fontWeight: '500',
  },
});

export default TenantDetails;

谢谢。我遇到了向右箭头未与右对齐的问题(下图)。另外,如何更改来具有标签和值(如果我有名字)?因此,当我单击它时,我可以打开。模态编辑值

屏幕: enter image description here

1 个答案:

答案 0 :(得分:1)

这是您代码的一部分。我添加了Left标签:

<Card>
  <View style={styles.containerTextHeader}>
       <Text style={styles.infoTextHeader}>Tenant Details</Text>
 </View>
 <CardItem>
     <Left>
       <Icon active name="logo-googleplus" />
       <Text>First Name</Text>
     </Left>
     <Right>
       <Icon name="arrow-forward" />
     </Right>
 </CardItem>
</Card>

对于模态问题,您可以通过react-native-modal安装npm install --save react-native-modal

CardItem上环绕一个按钮,您需要对其进行onPress。然后调用onPress,该方法可更改您的模式可见性状态。 像这样的代码:

   <Modal
       style={{ margin: 0 }}
       isVisible={this.state.modalVisible}
   />

要更改诸如name之类的字段,请使用组件状态