react-native-modal-dropdown icon indicating copy to clipboard operation
react-native-modal-dropdown copied to clipboard

Add PropType 'object' to options

Open hiphapis opened this issue 8 years ago • 2 comments

Currently only accept array. but some examples are use object So i add object of PropTypes

hiphapis avatar Nov 14 '17 07:11 hiphapis

have you tested object options. Not sure ListView datasource can accept it.

sohobloo avatar Feb 09 '18 11:02 sohobloo

@sohobloo Oops!! Sorry to late. Yes, we are already use it. I did check with official document about this, but i could not found. But fortunately i found example code. https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/RNTester/js/SwipeableListViewExample.js#L90 this code also use Hash

I will explain to you more In my case

render() {
  ...
  return (
    <ModalDropdown
      dropdownStyle={Styles.toolbarDropdown}
      dropdownTextStyle={Styles.toolbarSortLabel}
      animated={false}
      options={this.sortItems}
      onSelect={this.setSort}
    >
      <View style={Styles.toolbarSortWrapper}>
        <Text style={Styles.toolbarSortLabel}>{t(`products.sort.${sort}`)}</Text>
        <Icon name="dropdown" style={Styles.toolbarSortIcon} />
      </View>
    </ModalDropdown>
  )
}

get sortItems() {
  const t = this.props.translate

  const keys = ['recent',
    'lower_deposit', 'higher_deposit',
    'lower_amount', 'higher_amount',
  ]
  const hash = {}
  keys.forEach((key) => {
    hash[key] = t(`products.sort.${key}`)
  })
  return hash
}

setSort(sort) {
  if (this.state.sort !== sort) {
    const params = { ...this.state.params, sort, page: 1 }
    this.setState({ sort, page: 1, params })
    this.fetch(params)
  }
}

I did translate for sort options, this mean is sort values are change when users are change language For example, if you use English then value is 'recent', but if you change to Korea then value is change to '최신순' So we use Hash, you known just use hash key is good and better in this case

hiphapis avatar Mar 31 '18 02:03 hiphapis