Skip to content
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

Refactor GestureDetector #2901

Merged
merged 26 commits into from
May 16, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3a267b0
Move to separate directory
j-piasecki May 9, 2024
04ce6cb
Split into multiple files
j-piasecki May 9, 2024
5066297
Propagate relevant detector props to gestures helper
j-piasecki May 9, 2024
e2aca75
Use correct tense in error message
j-piasecki May 9, 2024
23d8caa
Small renames
j-piasecki May 9, 2024
4ba074b
More renames
j-piasecki May 9, 2024
f92267e
Warn when none of the callbacks are worklest, only throw in dev
j-piasecki May 9, 2024
d0d841b
More renames
j-piasecki May 9, 2024
91c4fc0
This one may be tricky, but I think the end result is the same
j-piasecki May 9, 2024
2626bb2
Move relations to helper
j-piasecki May 9, 2024
782ec5b
Rename `GestureConfigReference` -> `AttachedGestureState`
j-piasecki May 10, 2024
2d26817
Add comment
j-piasecki May 10, 2024
48d3397
Allow thread switching, no idea why it was disabled
j-piasecki May 10, 2024
16d4598
Don't show warning when no Reanimated
j-piasecki May 10, 2024
90c9a5f
Move mounted flag into the attached gesture state
j-piasecki May 10, 2024
9eee2b8
Rename and move assignment
j-piasecki May 10, 2024
3b07b17
Update src/handlers/gestures/GestureDetector/utils.ts
j-piasecki May 10, 2024
781f294
Update src/handlers/gestures/GestureDetector/index.tsx
j-piasecki May 10, 2024
d715f9c
Update src/handlers/gestures/GestureDetector/utils.ts
j-piasecki May 10, 2024
7f83166
Fix braces
j-piasecki May 10, 2024
007a0d9
More renames, move web handlers creation to hook
j-piasecki May 10, 2024
040e385
Add comment abount `blockHandler`
j-piasecki May 10, 2024
9ad420b
Extract more logic into hooks
j-piasecki May 10, 2024
d114ce4
Small optimizations
j-piasecki May 10, 2024
bab8167
Flatten ifs
j-piasecki May 14, 2024
067a8de
Remove validation from ref handler
j-piasecki May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
This one may be tricky, but I think the end result is the same
j-piasecki committed May 9, 2024

Verified

This commit was signed with the committer’s verified signature.
j-piasecki Jakub Piasecki
commit 91c4fc08e237b7a80bb8c6842a68a682632ff47e
6 changes: 1 addition & 5 deletions src/handlers/gestures/GestureDetector/attachHandlers.ts
Original file line number Diff line number Diff line change
@@ -35,11 +35,7 @@ export function attachHandlers({
webEventHandlersRef,
mountedRef,
}: AttachHandlersConfig) {
if (!preparedGesture.firstExecution) {
gestureConfig.initialize();
} else {
preparedGesture.firstExecution = false;
}
gestureConfig.initialize();
m-bert marked this conversation as resolved.
Show resolved Hide resolved

// use queueMicrotask to extract handlerTags, because all refs should be initialized
// when it's ran
8 changes: 1 addition & 7 deletions src/handlers/gestures/GestureDetector/index.tsx
Original file line number Diff line number Diff line change
@@ -142,7 +142,6 @@ export const GestureDetector = (props: GestureDetectorProps) => {
gesturesToAttach: gesturesToAttach,
animatedEventHandler: null,
animatedHandlers: null,
firstExecution: true,
shouldUseReanimated: shouldUseReanimated,
}).current;

@@ -189,16 +188,12 @@ export const GestureDetector = (props: GestureDetectorProps) => {
// Reanimated event should be rebuilt only when gestures are reattached, otherwise
// config update will be enough as all necessary items are stored in shared values anyway
const needsToRebuildReanimatedEvent =
preparedGesture.firstExecution ||
state.firstRender ||
needsToReattach(preparedGesture, gesturesToAttach) ||
state.forceReattach;

state.forceReattach = false;

if (preparedGesture.firstExecution) {
gestureConfig.initialize();
}

if (shouldUseReanimated) {
// Whether animatedGesture or gesture is used shouldn't change while the app is running
// eslint-disable-next-line react-hooks/rules-of-hooks
@@ -207,7 +202,6 @@ export const GestureDetector = (props: GestureDetectorProps) => {

useEffect(() => {
const viewTag = findNodeHandle(state.viewRef) as number;
state.firstRender = true;
mountedRef.current = true;

validateDetectorChildren(state.viewRef);
1 change: 0 additions & 1 deletion src/handlers/gestures/GestureDetector/types.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ export type GestureConfigReference = {
animatedHandlers: SharedValue<
HandlerCallbacks<Record<string, unknown>>[] | null
> | null;
firstExecution: boolean;
shouldUseReanimated: boolean;
};