-
Notifications
You must be signed in to change notification settings - Fork 734
Feat/SectionsWheelPicker new component #1260
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1ea3596
Feat/SectionsWheelPicker new component
lidord-wix 9ae1292
update prop name
lidord-wix 165d9bb
Merge branch 'master' into feat/sectionsWheelPicker_new_component
lidord-wix 814f7dc
fix some props passings
lidord-wix 54ea9c1
pass testID to the incubator wheelPicker
lidord-wix 11d4200
add testID to the incubator wheelPicker item
lidord-wix d3c2748
fix wheelPicker width
lidord-wix 78f6caa
Merge branch 'master' into feat/sectionsWheelPicker_new_component
lidord-wix 13f31a7
fix style
lidord-wix 5aee778
reorder imports
lidord-wix 07359b1
Merge branch 'master' into feat/sectionsWheelPicker_new_component
lidord-wix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
demo/src/screens/componentScreens/SectionsWheelPickerScreen.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import _ from 'lodash'; | ||
import React, {useState, useCallback} from 'react'; | ||
import {Alert} from 'react-native'; | ||
import {Text, View, SectionsWheelPicker, SegmentedControl, Button, Incubator} from 'react-native-ui-lib'; | ||
|
||
const SectionsWheelPickerScreen = () => { | ||
const [showMinutes, setShowMinutes] = useState(false); | ||
|
||
const [selectedDays, setSelectedDays] = useState(0); | ||
const [selectedHours, setSelectedHours] = useState(0); | ||
const [selectedMinutes, setSelectedMinutes] = useState(0); | ||
|
||
const days = _.times(10, i => i); | ||
const hours = _.times(24, i => i); | ||
const minutes = _.times(60, i => i); | ||
|
||
const getItems = useCallback(values => { | ||
return _.map(values, item => ({label: '' + item, value: item})); | ||
}, []); | ||
|
||
const onDaysChange = (item: number | string) => { | ||
setSelectedDays(item as number); | ||
}; | ||
|
||
const onHoursChange = (item: number | string) => { | ||
setSelectedHours(item as number); | ||
}; | ||
|
||
const onMinutesChange = (item: number | string) => { | ||
setSelectedMinutes(item as number); | ||
}; | ||
|
||
const onSavePress = () => { | ||
const days = selectedDays === 1 ? 'day' : 'days'; | ||
const hours = selectedHours === 1 ? 'hour' : 'hours'; | ||
const minutes = selectedMinutes === 1 ? 'minute' : 'minutes'; | ||
|
||
showMinutes | ||
? Alert.alert('Your chosen duration is:\n' + | ||
selectedDays + | ||
' ' + | ||
days + | ||
', ' + | ||
selectedHours + | ||
' ' + | ||
hours + | ||
' and ' + | ||
selectedMinutes + | ||
' ' + | ||
minutes) | ||
: Alert.alert('Your chosen duration is:\n' + selectedDays + ' ' + days + ' and ' + selectedHours + ' ' + hours); | ||
}; | ||
|
||
const onResetPress = () => { | ||
setSelectedDays(0); | ||
setSelectedHours(0); | ||
setSelectedMinutes(0); | ||
}; | ||
|
||
const sections: Incubator.WheelPickerProps[] = [ | ||
{items: getItems(days), onChange: onDaysChange, selectedValue: selectedDays, label: 'Days'}, | ||
{items: getItems(hours), onChange: onHoursChange, selectedValue: selectedHours, label: 'Hrs'}, | ||
{ | ||
items: getItems(minutes), | ||
onChange: onMinutesChange, | ||
selectedValue: selectedMinutes, | ||
label: 'Mins' | ||
} | ||
]; | ||
|
||
const sectionsToPresent = showMinutes ? sections : _.slice(sections, 0, 2); | ||
|
||
const onChangeIndex = (index: number) => { | ||
return index === 0 ? setShowMinutes(false) : setShowMinutes(true); | ||
}; | ||
|
||
return ( | ||
<View> | ||
<Text text40 marginL-10 marginT-20> | ||
Sections Wheel Picker | ||
</Text> | ||
<View centerH marginT-40> | ||
<SegmentedControl segments={[{label: '2 sections'}, {label: '3 sections'}]} onChangeIndex={onChangeIndex}/> | ||
<Text text50 marginV-20> | ||
Pick a duration | ||
</Text> | ||
</View> | ||
<SectionsWheelPicker sections={sectionsToPresent}/> | ||
<Button marginH-150 marginT-300 label={'Save'} onPress={onSavePress}/> | ||
<Button marginH-150 marginT-15 label={'Reset'} onPress={onResetPress}/> | ||
</View> | ||
); | ||
}; | ||
|
||
export default SectionsWheelPickerScreen; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import { TextStyle } from 'react-native'; | ||
import { WheelPickerProps } from '../../incubator'; | ||
export declare type SectionsWheelPickerProps = { | ||
/** | ||
* Array of sections. | ||
*/ | ||
sections?: WheelPickerProps[]; | ||
/** | ||
* Describe the height of each item in the WheelPicker | ||
* default value: 44 | ||
*/ | ||
itemHeight?: number; | ||
/** | ||
* Describe the number of rows visible | ||
* default value: 5 | ||
*/ | ||
numberOfVisibleRows?: number; | ||
/** | ||
* Text color for the focused row | ||
*/ | ||
activeTextColor?: string; | ||
/** | ||
* Text color for other, non-focused rows | ||
*/ | ||
inactiveTextColor?: string; | ||
/** | ||
* Row text style | ||
*/ | ||
textStyle?: TextStyle; | ||
testID?: string; | ||
}; | ||
declare const _default: React.ComponentClass<SectionsWheelPickerProps & { | ||
useCustomTheme?: boolean | undefined; | ||
}, any>; | ||
export default _default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { default as TabController } from './TabController'; | ||
export { default as TextField } from './TextField'; | ||
export { default as TouchableOpacity, TouchableOpacityProps } from './TouchableOpacity'; | ||
export { default as WheelPicker } from './WheelPicker'; | ||
export { default as WheelPicker, WheelPickerProps } from './WheelPicker'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import _ from 'lodash'; | ||
import React from 'react'; | ||
import {TextStyle} from 'react-native'; | ||
import {asBaseComponent} from '../../commons/new'; | ||
import View from '../view'; | ||
import {WheelPicker, WheelPickerProps} from '../../incubator'; | ||
|
||
export type SectionsWheelPickerProps = { | ||
/** | ||
* Array of sections. | ||
*/ | ||
sections?: WheelPickerProps[]; | ||
/** | ||
* Describe the height of each item in the WheelPicker | ||
* default value: 44 | ||
*/ | ||
itemHeight?: number; | ||
/** | ||
* Describe the number of rows visible | ||
* default value: 5 | ||
*/ | ||
numberOfVisibleRows?: number; | ||
/** | ||
* Text color for the focused row | ||
*/ | ||
activeTextColor?: string; | ||
/** | ||
* Text color for other, non-focused rows | ||
*/ | ||
inactiveTextColor?: string; | ||
/** | ||
* Row text style | ||
*/ | ||
textStyle?: TextStyle; | ||
testID?: string; | ||
}; | ||
|
||
/** | ||
* @description: SectionsWheelPicker component for presenting set of wheelPickers | ||
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/SectionsWheelPickerScreen.tsx | ||
*/ | ||
|
||
const SectionsWheelPicker = (props: SectionsWheelPickerProps) => { | ||
const {sections, itemHeight, numberOfVisibleRows, activeTextColor, inactiveTextColor, textStyle, testID} = props; | ||
|
||
const wheelPickerProps = { | ||
itemHeight, | ||
numberOfVisibleRows, | ||
activeTextColor, | ||
inactiveTextColor, | ||
textStyle | ||
}; | ||
|
||
const renderSections = () => | ||
_.map(sections, (section, index) => { | ||
return ( | ||
<View height={1} key={index} testID={testID}> | ||
<WheelPicker testID={`${testID}.${index}`} {...wheelPickerProps} {...section}/> | ||
</View> | ||
); | ||
}); | ||
|
||
return ( | ||
<View flex row centerH> | ||
{renderSections()} | ||
</View> | ||
); | ||
}; | ||
|
||
SectionsWheelPicker.displayName = 'SectionsWheelPicker'; | ||
|
||
export default asBaseComponent<SectionsWheelPickerProps>(SectionsWheelPicker); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.