picker icon indicating copy to clipboard operation
picker copied to clipboard

Can't place the Picker on beside text when 'flexDirection' is row.

Open lightning331 opened this issue 5 years ago • 4 comments
trafficstars

My example code:

...
  render() {
    return (
      <View style={styles.container}>
        <Text>Height</Text>
        <Text style={styles.result_text}>170</Text>
        <Picker
          selectedValue={this.state.unit}
          style={{height: 50, width: 100}}
          itemStyle={{textAlign: 'left', fontSize: 14}}
          onValueChange={(itemValue, itemIndex) =>
            this.setState({unit: itemValue})
          }>
          <Picker.Item label="cm" value="cm" />
          <Picker.Item label="feet, inches" value="feet" />
        </Picker>
      </View>
    );
...
const styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
    alignItems: 'center',
  },
}
  • Screenshot image

lightning331 avatar Feb 22 '20 15:02 lightning331

try to wrap <Picker> component with <View> component

hakkikonu avatar Apr 04 '20 12:04 hakkikonu

Can you try this

 <View
        style={{
          flexDirection: "row",
          alignItems: "center",
        }}
      >
        <Text>Language:</Text>
        <PickerIOS
          style={{ flex: 1 }}
          mode="dialog"
          itemStyle={{ fontWeight: "bold", color: "#ff0000" }}
          selectedValue={this.state.language}
          onValueChange={(itemValue, itemIndex) =>
            this.setState({ language: itemValue })
          }
        >
          <PickerIOS.Item label="Java" value="java" />
          <PickerIOS.Item label="JavaScript" value="js" />
        </PickerIOS>
      </View>

image

jainkuniya avatar May 10 '20 06:05 jainkuniya

Is there a solution for Android?

I tried

const Task = ({route}) => (
  <ScrollView>
    <View
      style={tw`flex flex-row justify-between items-center bg-white border border-gray-200`}
    >
      <Text>Task state</Text>
      <Picker>
        <Picker.Item label="NEXT" value="NEXT" />
        <Picker.Item label="INPROGRESS" value="INPROGRESS" />
      </Picker>
    </View>
  </ScrollView>
);

and launched the app in Android, which looks like this. But the problem is that clicking on the picker results in nothing, i.e. the selections don't show up.

Screen Shot 2022-01-23 at 12 05 28

x-ji avatar Jan 23 '22 11:01 x-ji

I made it work according to this: https://stackoverflow.com/a/42851316/1460448. Setting flex:.5 on both the Text and the Picker was the key.

x-ji avatar Jan 23 '22 11:01 x-ji