-
Notifications
You must be signed in to change notification settings - Fork 63
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
react-native for web support #31
base: master
Are you sure you want to change the base?
Conversation
alexkendall
commented
Jun 9, 2022
- Adds support to snap to items on react-native for web
- Integrates hooks logic to get current index while scrolling events take place
- Snaps to items automatically after a 500ms timeout on web
- Only runs additional hooks code on web to keep performance the same on mobile
@alexkendall Thanks for contributing! I'll check out the changes as soon as possible. |
src/WheelPicker.tsx
Outdated
}, [scrollIndex]) | ||
|
||
const handleScroll = (event: { | ||
nativeEvent: { |
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.
use the type Animated.EventConfig<NativeScrollEvent>
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.
This should be updated now.
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.
please also update the other occurence
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.
Updated.
src/WheelPicker.tsx
Outdated
@@ -88,6 +93,47 @@ const WheelPicker: React.FC<Props> = ({ | |||
} | |||
}; | |||
|
|||
useEffect(() => { | |||
if (Platform.OS === "web") { | |||
const SCROLL_COOLDOWN_MILISECONDS = 100 |
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.
typo MILISECONDS
=> MILLISECONDS
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.
This should be updated now.
src/WheelPicker.tsx
Outdated
if (difference > SCROLL_DID_STOP_TIMEOUT) { | ||
flatList.current?.scrollToIndex({ index: scrollIndex, animated: true }) | ||
} | ||
}, SCROLL_COOLDOWN_MILISECONDS) |
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.
typo MILISECONDS
=> MILLISECONDS
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.
This should be updated now.
src/WheelPicker.tsx
Outdated
@@ -54,8 +55,12 @@ const WheelPicker: React.FC<Props> = ({ | |||
containerProps = {}, | |||
}) => { | |||
const [scrollY] = useState(new Animated.Value(0)); | |||
const flatList = useRef<any>(null) |
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.
should have a type
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.
should be called flatListRef
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.
Updated to use flatListRef
src/WheelPicker.tsx
Outdated
|
||
useEffect(() => { | ||
if (Platform.OS === "web") { | ||
if (onChange) { |
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.
onChange
is not nullable
src/WheelPicker.tsx
Outdated
} | ||
}) => { | ||
if (Platform.OS === "web") { | ||
const positionY = event?.nativeEvent?.contentOffset?.y ?? 0; |
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.
remove the ?
, these types are not nullable
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.
The ?
's have been removed.
src/WheelPicker.tsx
Outdated
@@ -54,8 +55,12 @@ const WheelPicker: React.FC<Props> = ({ | |||
containerProps = {}, | |||
}) => { | |||
const [scrollY] = useState(new Animated.Value(0)); | |||
const flatList = useRef<any>(null) | |||
|
|||
const lastScrollTimestamp = useRef(new Date().getTime()) |
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.
missing semicolon, please format the code with yarn prettier --write src
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.
Reformatted with the latest commit.
src/WheelPicker.tsx
Outdated
contentSize: { height: number, width: number }, | ||
layoutMeasurement: { height: number, width: number } | ||
} | ||
}) => handleScroll(event) }, |
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.
code formatting
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.
Reformatted with the latest commit.
9c7b8f1
to
6e18de8
Compare
Snaps to item automatically on react-native-web with usage of cooldown.
@erksch Went ahead and rebased and squashed the commits to clean up the history and rebased with master. I had to make a few changes to the scroll event to get the typescript to build without errors, and adding the Animated types did not work. It should compile without errors now. |
@erksch is it possible to get this merged? |
Is there any hope to get this merged any time soon? Thank you. |
Hello.... Any news on this PR? When can we merge this? |
Thanks @alexkendall for working on this. I'm hoping to use react-native-wheely in an Expo Web enabled project. @erksch any chance we can get this merged and into a release? |
@erksch I tested this in Expo Web, and it works. Would be great to get this merged and into a release soon. If anyone else wants to try out this change right now, here's what I did (starting in Expo project's base directory):
A bit annoying to install, but it works. |