-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[Web] Native detector component #3637
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
Open
akwasniewski
wants to merge
58
commits into
next
Choose a base branch
from
@akwasniewski/native-detector-web
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 52 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
ea8bd73
basic component
akwasniewski 32fea07
Merge branch 'next' into @akwasniewski/native-detector-web
akwasniewski 968112c
better useffect triggers:
akwasniewski 6a69cd7
added todos
akwasniewski 2b404af
moved Gesture handler detectors
akwasniewski 9c30c1a
path fix
akwasniewski d7dd057
extracted host gesture detector
akwasniewski 56b93d3
not extending view props
akwasniewski ad8ef64
native detector action type
akwasniewski 0304177
moved implementation of web handler
akwasniewski 4aaf700
memoisation
akwasniewski eeddd24
detaching handlers
akwasniewski 3242ffd
forgot to asign to oldHandlerTags
akwasniewski 7147ab3
removed unnecessary types
akwasniewski cc78f74
native detector animated event action type
akwasniewski 067becb
removed console log
akwasniewski d782c95
handling animated events in sendEvents
akwasniewski 86046bd
first refactor
akwasniewski 6c34d33
using native detector animated event
akwasniewski cd793b3
refactor 2
akwasniewski 580494d
use callback in native detector
akwasniewski eb98bf4
tagMessage
akwasniewski af663c8
should prevent drop
akwasniewski 42e84b4
old api compatibility
akwasniewski 079fdb4
not throwing strings
akwasniewski cb72d7e
removed unnessary check
akwasniewski de98017
even more refactoring
akwasniewski e193ff4
throwing when propsref is null
akwasniewski 2ba053a
helper action type functions
akwasniewski 8ab666b
separate paths on touch events
akwasniewski c445262
removed unsafe memoisation
akwasniewski 46a9570
props extending
akwasniewski 37c4070
failing on detach
akwasniewski 20cbc9e
one more refactor
akwasniewski 58f8d60
display contents
akwasniewski 532f35a
Merge branch 'next' into @akwasniewski/native-detector-web
akwasniewski 7d205dc
removed action type native detector animated event
akwasniewski 0c6f200
Update packages/react-native-gesture-handler/src/web/tools/GestureHan…
akwasniewski 00738d6
minor fixes
akwasniewski 9c17a96
type predicate
akwasniewski 2353a84
readded memoisation
akwasniewski 2443971
changed dependencies
akwasniewski f3198f5
moved forAnimated to config
akwasniewski 686fadd
removed forAnimated from attachHandlers
akwasniewski b0d384d
type predicate using protected props ref
akwasniewski 2ba5ae8
native gesture bugfix
akwasniewski 38b240a
Merge branch 'next' into @akwasniewski/native-detector-web
akwasniewski 7c00105
removed forAnimated
akwasniewski dceba3b
Merge branch 'next' into @akwasniewski/native-detector-web
akwasniewski b738254
removed usecallback
akwasniewski 1f62d5c
private isInitialized
akwasniewski 4d916f5
removed type predicate
akwasniewski 18b1b77
safe detaching
akwasniewski 5fdd932
minor fixes in GestureHandler
akwasniewski a5febe8
view getter
akwasniewski 9ad8c0e
fix
akwasniewski 10ce758
safer
akwasniewski 1cd4bf1
forAnimated defaults to false
akwasniewski 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
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
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
3 changes: 3 additions & 0 deletions
3
packages/react-native-gesture-handler/src/v3/HostGestureDetector.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,3 @@ | ||
import RNGestureHandlerDetectorNativeComponent from '../specs/RNGestureHandlerDetectorNativeComponent'; | ||
const HostGestureDetector = RNGestureHandlerDetectorNativeComponent; | ||
export default HostGestureDetector; |
63 changes: 63 additions & 0 deletions
63
packages/react-native-gesture-handler/src/v3/HostGestureDetector.web.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,63 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import { View } from 'react-native'; | ||
import RNGestureHandlerModule from '../RNGestureHandlerModule.web'; | ||
import { ActionType } from '../ActionType'; | ||
import { PropsRef } from '../web/interfaces'; | ||
|
||
export interface GestureHandlerDetectorProps extends PropsRef { | ||
handlerTags: number[]; | ||
moduleId: number; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const HostGestureDetector = (props: GestureHandlerDetectorProps) => { | ||
const { handlerTags, children } = props; | ||
|
||
const viewRef = useRef(null); | ||
const propsRef = useRef<PropsRef>(props); | ||
const attachedHandlerTags = useRef<Set<number>>(new Set<number>()); | ||
|
||
const detachHandlers = (oldHandlerTags: Set<number>) => { | ||
oldHandlerTags.forEach((tag) => { | ||
RNGestureHandlerModule.detachGestureHandler(tag); | ||
}); | ||
}; | ||
|
||
const attachHandlers = (currentHandlerTags: Set<number>) => { | ||
const oldHandlerTags = | ||
attachedHandlerTags.current.difference(currentHandlerTags); | ||
const newHandlerTags = currentHandlerTags.difference( | ||
attachedHandlerTags.current | ||
); | ||
|
||
detachHandlers(oldHandlerTags); | ||
|
||
newHandlerTags.forEach((tag) => { | ||
RNGestureHandlerModule.attachGestureHandler( | ||
tag, | ||
viewRef.current, | ||
ActionType.NATIVE_DETECTOR, | ||
akwasniewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
propsRef | ||
); | ||
}); | ||
attachedHandlerTags.current = currentHandlerTags; | ||
}; | ||
|
||
useEffect(() => { | ||
attachHandlers(new Set(handlerTags)); | ||
}, [handlerTags]); | ||
|
||
useEffect(() => { | ||
return () => { | ||
detachHandlers(attachedHandlerTags.current); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<View style={{ display: 'contents' }} ref={viewRef}> | ||
{children} | ||
</View> | ||
); | ||
}; | ||
|
||
export default HostGestureDetector; |
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.
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.