Skip to content

Commit

Permalink
Make gesture required prop in GestureDetector (#2285)
Browse files Browse the repository at this point in the history
## Description

This PR brings small change to `GestureDetector`. It changes currently
optional `gesture` prop to be required. I believe it is pointless to
keep it as optional, since using `GestureDetector` without gestures
doesn't make much sense.

## Test plan

Tested on example app.

Co-authored-by: Michał Bert <[email protected]>
Co-authored-by: Jakub Piasecki <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2022
1 parent 1b57803 commit a8539d2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/handlers/gestures/GestureDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ interface WebEventHandler {

interface AttachHandlersConfig {
preparedGesture: GestureConfigReference;
gestureConfig: ComposedGesture | GestureType | undefined;
gestureConfig: ComposedGesture | GestureType;
gesture: GestureType[];
viewTag: number;
webEventHandlersRef: React.RefObject<WebEventHandler>;
Expand All @@ -140,15 +140,15 @@ function attachHandlers({
webEventHandlersRef,
}: AttachHandlersConfig) {
if (!preparedGesture.firstExecution) {
gestureConfig?.initialize();
gestureConfig.initialize();
} else {
preparedGesture.firstExecution = false;
}

// use setImmediate to extract handlerTags, because all refs should be initialized
// when it's ran
setImmediate(() => {
gestureConfig?.prepare();
gestureConfig.prepare();
});

for (const handler of gesture) {
Expand Down Expand Up @@ -228,11 +228,11 @@ function attachHandlers({

function updateHandlers(
preparedGesture: GestureConfigReference,
gestureConfig: ComposedGesture | GestureType | undefined,
gestureConfig: ComposedGesture | GestureType,
gesture: GestureType[],
mountedRef: RefObject<boolean>
) {
gestureConfig?.prepare();
gestureConfig.prepare();

for (let i = 0; i < gesture.length; i++) {
const handler = preparedGesture.config[i];
Expand Down Expand Up @@ -584,18 +584,18 @@ const applyUserSelectProp = (
};

interface GestureDetectorProps {
gesture?: ComposedGesture | GestureType;
gesture: ComposedGesture | GestureType;
userSelect?: UserSelect;
children?: React.ReactNode;
}
export const GestureDetector = (props: GestureDetectorProps) => {
const gestureConfig = props.gesture;

if (props.userSelect && gestureConfig) {
if (props.userSelect) {
applyUserSelectProp(props.userSelect, gestureConfig);
}

const gesture = gestureConfig?.toGestureArray?.() ?? [];
const gesture = gestureConfig.toGestureArray();
const useReanimatedHook = gesture.some((g) => g.shouldUseReanimated);
const viewRef = useRef(null);
const firstRenderRef = useRef(true);
Expand Down Expand Up @@ -633,7 +633,7 @@ export const GestureDetector = (props: GestureDetectorProps) => {
preparedGesture.firstExecution || needsToReattach(preparedGesture, gesture);

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

if (useReanimatedHook) {
Expand Down

0 comments on commit a8539d2

Please sign in to comment.