Skip to content
This repository has been archived by the owner on Mar 4, 2019. It is now read-only.

Commit

Permalink
Refactor: The OptionPicker
Browse files Browse the repository at this point in the history
- change ScrollView to FlatList
- fix autoFocus props
  • Loading branch information
FilipMessa authored and RobinCsl committed Feb 22, 2019
1 parent 0fbdb90 commit 0205a85
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/OptionPicker/OptionPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function OptionPicker(props: Props) {
<View>
<View style={styles.inputWrapper}>
<TagsInput
autofocus
autoFocus
tags={tags}
onClearPress={onClearPress}
value={text}
Expand Down
12 changes: 8 additions & 4 deletions src/OptionPicker/OptionPicker.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ storiesOf('OptionPicker', module)
const onClearPress = action('onClearPress');
const onPressAdd = action('onPressAdd');
const onPressItem = action('onPressItem');
const selected = select('selected', {
None: null,
Prague: [Prague],
});
const selected = select(
'selected',
{
None: null,
Prague: [Prague],
},
null,
);
const options = object('Options', mockedPlaces);
const label = text('label', 'From:');
const placeholder = text('placeholder', 'Departure point');
Expand Down
2 changes: 1 addition & 1 deletion src/OptionPicker/OptionPickerTypes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

export type OptionType = {
+id: string | number,
+id: string,
+label: string,
+text: ?string,
+type: 'localization' | 'destination' | 'airplane' | 'bus' | 'train', // @TODO use IconNameType as enum types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ exports[`OptionPicker render 1`] = `
}
>
<TagsInput
autofocus={true}
autoCorrect={false}
autoFocus={true}
fontSize={16}
label="label"
onChangeText={
Expand Down
35 changes: 23 additions & 12 deletions src/OptionPicker/components/OptionList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import * as React from 'react';
import { ScrollView } from 'react-native';
import { FlatList, Keyboard } from 'react-native';

import Option from './Option';
import { areSelectedOptionsChanged } from '../helpers';
Expand All @@ -20,20 +20,31 @@ export default class OptionList extends React.Component<Props> {
return areSelectedOptionsChanged(options, nextProps.options);
}

renderOption = ({ item }: { item: OptionType }) => {
const { onItemPress, onAddPress } = this.props;
return (
<Option
option={item}
key={item.id}
onItemPress={onItemPress}
onAddPress={onAddPress}
/>
);
};

keyExtractor = (item: OptionType) => item.id;

render() {
const { options, onItemPress, onAddPress } = this.props;
const { options } = this.props;

return (
<ScrollView>
{options.map(option => (
<Option
option={option}
key={option.id}
onItemPress={onItemPress}
onAddPress={onAddPress}
/>
))}
</ScrollView>
<FlatList
keyboardShouldPersistTaps="always"
onScroll={Keyboard.dismiss}
data={options}
renderItem={this.renderOption}
keyExtractor={this.keyExtractor}
/>
);
}
}

0 comments on commit 0205a85

Please sign in to comment.