-
Notifications
You must be signed in to change notification settings - Fork 734
Infra/ Incubator.WheelPicker selectedValue #1782
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,9 @@ export enum WheelPickerAlign { | |
|
||
export interface WheelPickerProps { | ||
/** | ||
* Initial value (doesn't work with selectedValue) | ||
* Initial value | ||
*/ | ||
initialValue?: ItemProps | number | string; | ||
/** | ||
* The current selected value | ||
*/ | ||
selectedValue?: ItemProps | number | string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking change. I know we're in the incubator but I'm thinking that we might want to at least explain to the uses what's wrong. Maybe add a deprecated message or error them when we detect they passed this prop... or we rely on the ts errors alone? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have any internal users using this feature, regarding the community - we will add it under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SectionsWheelPicker is using this component and it is not in the incubator. If someone passed 'selectedValue' to one of the sections (type WheelPickerProps) it will be affected by this change. How do we deal with that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, but there's no internal use for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually don't introduce breaking changes in minor versions. Let's discuss this with @ethanshar There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's ok, that's why we have the Incubator components. Moreover, this breaking change do offer an easy alternative and the community can also lock version till they handle the change. |
||
/** | ||
* Data source for WheelPicker | ||
*/ | ||
|
@@ -99,8 +95,7 @@ const WheelPicker = ({ | |
align = WheelPickerAlign.CENTER, | ||
style, | ||
children, | ||
initialValue, | ||
selectedValue, | ||
initialValue = 0, | ||
testID | ||
}: WheelPickerProps) => { | ||
const scrollView = useRef<Animated.ScrollView>(); | ||
|
@@ -112,12 +107,10 @@ const WheelPicker = ({ | |
const { | ||
height, | ||
items, | ||
shouldControlComponent, | ||
index: currentIndex, | ||
getRowItemAtOffset | ||
} = usePresenter({ | ||
initialValue, | ||
selectedValue, | ||
items: propItems, | ||
children, | ||
itemHeight, | ||
|
@@ -126,17 +119,9 @@ const WheelPicker = ({ | |
|
||
const prevInitialValue = useRef(initialValue); | ||
const prevIndex = useRef(currentIndex); | ||
const [scrollOffset, setScrollOffset] = useState(currentIndex * itemHeight); | ||
const [flatListWidth, setFlatListWidth] = useState(0); | ||
const keyExtractor = useCallback((item: ItemProps, index: number) => `${item}.${index}`, []); | ||
|
||
useEffect(() => { | ||
// This effect enforce the index to be controlled by selectedValue passed by the user | ||
if (shouldControlComponent(scrollOffset)) { | ||
scrollToIndex(currentIndex, true); | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
// This effect making sure to reset index if initialValue has changed | ||
!isUndefined(initialValue) && scrollToIndex(currentIndex, true); | ||
|
@@ -149,13 +134,14 @@ const WheelPicker = ({ | |
} else { | ||
onChange?.(value, index); | ||
} | ||
}, [initialValue, onChange]); | ||
}, | ||
[initialValue, onChange]); | ||
|
||
const onValueChange = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => { | ||
setScrollOffset(event.nativeEvent.contentOffset.y); | ||
const {index, value} = getRowItemAtOffset(event.nativeEvent.contentOffset.y); | ||
_onChange(value, index); | ||
}, [_onChange, getRowItemAtOffset]); | ||
}, | ||
[_onChange, getRowItemAtOffset]); | ||
|
||
const onMomentumScrollEndAndroid = (index: number) => { | ||
// handle Android bug: ScrollView does not call 'onMomentumScrollEnd' when scrolled programmatically (https://github.com/facebook/react-native/issues/26661) | ||
|
@@ -188,7 +174,8 @@ const WheelPicker = ({ | |
|
||
const selectItem = useCallback(index => { | ||
scrollToIndex(index, true); | ||
}, [itemHeight]); | ||
}, | ||
[itemHeight]); | ||
|
||
const renderItem = useCallback(({item, index}) => { | ||
return ( | ||
|
@@ -208,11 +195,13 @@ const WheelPicker = ({ | |
testID={`${testID}.item_${index}`} | ||
/> | ||
); | ||
}, [itemHeight]); | ||
}, | ||
[itemHeight]); | ||
|
||
const getItemLayout = useCallback((_data, index: number) => { | ||
return {length: itemHeight, offset: itemHeight * index, index}; | ||
}, [itemHeight]); | ||
}, | ||
[itemHeight]); | ||
|
||
const updateFlatListWidth = useCallback((width: number) => { | ||
setFlatListWidth(width); | ||
|
@@ -254,7 +243,8 @@ const WheelPicker = ({ | |
|
||
const fader = useMemo(() => (position: FaderPosition) => { | ||
return <Fader visible position={position} size={60}/>; | ||
}, []); | ||
}, | ||
[]); | ||
|
||
const separators = useMemo(() => { | ||
return ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this example? Looks like the days example so we don't really need both now, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add an example for changing 'initialValue' to show its effect, like a button that rolls the wheel by changing the prop's value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we had the months example originally, maybe for string values.
Anyway, I've added two buttons for updating the years value with the
initialValue
.