Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PropType 'object' to options #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hiphapis
Copy link

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

Currently only accept `array`. but some examples are use `object`
So i add `object` of PropTypes
@sohobloo
Copy link
Owner

sohobloo commented Feb 9, 2018

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

@hiphapis
Copy link
Author

hiphapis commented Mar 31, 2018

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants