react-native-maps#Circle TypeScript Examples

The following examples show how to use react-native-maps#Circle. 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: CreateScreen.tsx    From lets-fork-native with MIT License 4 votes vote down vote up
CreateScreen = React.memo((props: Props): React.ReactElement => {
  const locale = getLocale()
  const countries = ['LR', 'MM', 'US']
  const system = countries.includes(locale.substring(3)) ? 'imperial' : 'metric'

  const units = UNITS.units[system]
  const conversion = UNITS.conversion[system]
  const symbol = currencies[locale.substring(3)] || '$'

  const { location, navigation, ws } = props
  const [categories, setCategories] = React.useState<string[]>([])
  const [price, setPrice] = React.useState([false, false, false, false])
  const [openNow, setOpenNow] = React.useState(true)
  const [radius, setRadius] = React.useState(UNITS.initialRadius[system])
  const [region, setRegion] = React.useState({
    latitude: location?.coords?.latitude || 52.520008,
    longitude: location?.coords?.longitude || 13.404954,
    latitudeDelta: 0.01,
    longitudeDelta: 0.1,
  })

  // creates a new party
  const handleCreate = (): void => {
    const pr: number[] = []
    price.forEach((p, i) => {
      if (p) pr.push(i + 1)
    })

    ws.send(JSON.stringify({
      type: 'create',
      payload: {
        categories: categories.length ? categories.join(',') : 'restaurants',
        latitude: `${region.latitude}`,
        longitude: `${region.longitude}`,
        radius: `${radius}`,
        open_now: openNow,
        price: pr.length ? pr : null,
      },
    }))
    navigation.navigate('Party')
  }

  return (
    <ScrollView>
      <MapView
        style={styles.map}
        region={region}
        onRegionChangeComplete={setRegion}
        rotateEnabled={false}
        scrollEnabled
        zoomEnabled
      >
        <Circle
          center={region}
          radius={radius}
        />
      </MapView>
      <Text style={styles.radius}>
        {`Find restaurants within: ${(radius / conversion).toFixed(1)}${units}`}
      </Text>
      <Slider
        style={styles.slider}
        minimumValue={UNITS.minimumValue[system]}
        maximumValue={UNITS.maximumValue[system]}
        minimumTrackTintColor={colors.green}
        maximumTrackTintColor={colors.green}
        value={radius}
        onValueChange={setRadius}
        step={UNITS.step[system]}
      />
      <View style={styles.openNow}>
        <Switch
          style={styles.switch}
          value={openNow}
          onValueChange={setOpenNow}
        />
        <Text style={styles.openNowText}>{openNow ? 'Currently open' : 'All restaurants'}</Text>
      </View>
      <View style={styles.price}>
        <Price selected={price} setSelected={setPrice} n={1}>{symbol}</Price>
        <Price selected={price} setSelected={setPrice} n={2}>{symbol}</Price>
        <Price selected={price} setSelected={setPrice} n={3}>{symbol}</Price>
        <Price selected={price} setSelected={setPrice} n={4}>{symbol}</Price>
      </View>
      <MultiSelect
        handleSelect={setCategories}
        items={CATEGORIES}
      />
      <View style={styles.button}>
        <Button color="purple" size="sm" onPress={(): void => handleCreate()}>
          CREATE
        </Button>
      </View>
    </ScrollView>
  )
})