简体   繁体   English

反应本机选择器问题

[英]React Native picker issue

Am unable to set Picker in middle of the screen on iPhone even querying in google and Udemy I did not get a solution. 我无法在iPhone的屏幕中间设置Picker,即使在google和Udemy中查询也没有解决方案。 Please Help me guys. 请帮助我。 I hope you guys will help me in this React Native picker issue. 我希望你们能在我的React Native Picker问题上帮助我。 Am trying to solve this issue from last week but couldn't do so guys please help me. 我正在尝试从上周开始解决此问题,但不能这样做,请大家帮帮我。

EmployeeCreate 员工创建

import React, { Component } from 'react';
import { Picker, Text } from 'react-native';
import { connect } from 'react-redux';
import { employeeUpdate } from '../actions';
import { Card, CardSection, Input, Button } from './common';

class EmployeeCreate extends Component {
  render() {
    return (
      <Card>
        <CardSection>
          <Input
            label="Name"
            placeholder="Jane"
            value={this.props.name}
            onChangeText={value => this.props.employeeUpdate({ prop: 'name', value })}
          />
        </CardSection>

        <CardSection>
          <Input
            label="Phone"
            placeholder="555-555-555"
            value={this.props.phone}
            onChangeText={value => this.props.employeeUpdate({ prop: 'phone', value })}
          />
        </CardSection>

        <CardSection style={‌{ flexDirection: 'column', }}>
          <Text style={styles.pickerTextStyle}>Shift</Text>
          <Picker
            style={‌{ flex: 1 }}
            selectedValue={this.props.shift}
            onValueChange={value => this.props.employeeUpdate({ prop: 'shift', value })}
          >
          <Picker.Item label="Monday" value="Monday" />
          <Picker.Item label="Tuesday" value="Tuesday" />
          <Picker.Item label="Wednesday" value="Wednesday" />
          <Picker.Item label="Thursday" value="Thursday" />
          <Picker.Item label="Friday" value="Friday" />
          <Picker.Item label="Saturday" value="Saturday" />
          <Picker.Item label="Sunday" value="sunday" />
          </Picker>
        </CardSection>

        <CardSection>
          <Button>
            Create
          </Button>
        </CardSection>
      </Card>
    );
  }
}

const styles = {
  pickerTextStyles: {
    fontSize: 18,
    paddingLeft: 20
  }
};

const mapStateToProps = (state) => {
  const { name, phone, shift } = state.employeeForm;
  return { name, phone, shift };
};
export default connect(mapStateToProps, { employeeUpdate })(EmployeeCreate);

CardSection 卡片部分

import React from 'react';
import { View } from 'react-native';

const CardSection = (props) => {
  return (
    <View style={[styles.containerStyle, props.style]}>
      {props.children}
    </View>
  );
};

const styles = {
  containerStyle: {
    borderBottomWidth: 1,
    padding: 5,
    backgroundColor: '#fff',
    justifyContent: 'flex-start',
    flexDirection: 'row',
    borderColor: '#ddd',
    position: 'relative'
  }
};

export { CardSection };

Screenshot : 屏幕截图:

反应本机选择器问题

Picker is not in the center because on left side you have shift text. 选取器不在中心,因为在左侧您有班次文本。 If you want to make picker in the center then you have to set width of the picker. 如果要在中心放置拾取器,则必须设置拾取器的宽度。

Try changing the width of the picker = width of screen - 2 * (width of text) 尝试更改选择器的宽度=屏幕宽度-2 *(文本宽度)

If it is not possible to change the width of a picker then set the left margin of the picker = negative value of width of the shift text 如果无法更改选择器的宽度,则将选择器的左边距设置为班次文本宽度的负值

and increase the left padding to picker text value so that shift text will not overlap picker value 并增加选择器文本值的左侧填充,以使移位文本不会与选择器值重叠

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM