react-native#Picker TypeScript Examples

The following examples show how to use react-native#Picker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: App.tsx    From react-native-giphy-ui with MIT License 4 votes vote down vote up
export default function App() {
  const [gif, setGif] = useState<GiphyGif | undefined>();
  const [theme, setTheme] = useState<GiphyTheme>();
  const [rating, setRating] = useState<GiphyUIRating>('ratedPG');
  const [mediaTypes, setMediaTypes] = useState<GiphyMediaType[]>(['gifs']);
  const [shouldLocalizeSearch, setShouldLocalizeSearch] = useState(false);
  const [showConfirmationScreen, setShowConfirmationScreen] = useState(false);
  const [useNativeMediaView] = useState(false);

  const openGifPicker = useCallback(() => {
    setGif(undefined);
    GiphyUi.present(
      {
        mediaTypes,
        theme,
        rating,
        showConfirmationScreen,
        shouldLocalizeSearch,
      },
      setGif
    );
  }, [mediaTypes, theme, rating, showConfirmationScreen, shouldLocalizeSearch]);

  return (
    <>
      <ScrollView
        style={styles.container}
        contentContainerStyle={styles.content}
        contentInset={{ bottom: 500 }}
      >
        {gif && (
          <View style={styles.gif}>
            <Text style={styles.gifTitle}>
              Selected Gif {useNativeMediaView && '(Native View)'}
            </Text>
            {useNativeMediaView ? (
              <GiphyMediaView media={gif} />
            ) : (
              <Image
                source={{ uri: gif.images.downsized.url }}
                style={styles.gifImage}
              />
            )}
          </View>
        )}
        <View style={styles.settings}>
          <View style={styles.setting}>
            <Text style={styles.settingTitle}>Theme</Text>
            <Picker
              selectedValue={theme}
              onValueChange={value => setTheme(value)}
              style={styles.picker}
            >
              <Picker.Item label="Light" value="light" />
              <Picker.Item label="Dark" value="dark" />
            </Picker>
          </View>
          <View style={styles.setting}>
            <Text style={styles.settingTitle}>Media Types</Text>
            <Picker
              selectedValue={mediaTypes[0]}
              onValueChange={value => setMediaTypes([value])}
              style={styles.picker}
            >
              <Picker.Item label="Gifs" value="gifs" />
              <Picker.Item label="Emojis" value="emoji" />
              <Picker.Item label="Stickers" value="stickers" />
              <Picker.Item label="Text" value="text" />
            </Picker>
          </View>
          <View style={styles.setting}>
            <Text style={styles.settingTitle}>Rating</Text>
            <Picker
              selectedValue={rating}
              onValueChange={value => setRating(value)}
              style={styles.picker}
            >
              <Picker.Item label="PG" value="ratedPG" />
              <Picker.Item label="PG 13" value="ratedPG13" />
              <Picker.Item label="Unrated" value="unrated" />
              <Picker.Item label="Rated R" value="ratedR" />
              <Picker.Item label="Rated Y" value="ratedY" />
              <Picker.Item label="Rated G" value="ratedG" />
              <Picker.Item label="NSFW" value="nsfw" />
            </Picker>
          </View>
          {Platform.OS === 'ios' && (
            <>
              <View style={styles.settingRow}>
                <Text style={styles.settingTitle}>
                  Show Confirmation Screen
                </Text>
                <Switch
                  value={showConfirmationScreen}
                  onValueChange={setShowConfirmationScreen}
                />
              </View>
              <View style={styles.settingRow}>
                <Text style={styles.settingTitle}>Localize Search</Text>
                <Switch
                  value={shouldLocalizeSearch}
                  onValueChange={setShouldLocalizeSearch}
                />
              </View>
              {/* <View style={styles.settingRow}>
                <Text style={styles.settingTitle}>Use Native Media View</Text>
                <Switch
                  value={useNativeMediaView}
                  onValueChange={setUseNativeMediaView}
                />
              </View> */}
            </>
          )}
        </View>
      </ScrollView>
      <View style={styles.float}>
        <Button onPress={openGifPicker} title="Open Gif Picker" />
      </View>
    </>
  );
}