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

Unify comments and simplify some conditions. #2984

Merged
merged 9 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
4 changes: 2 additions & 2 deletions src/Directions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const LEFT = 2;
const UP = 4;
const DOWN = 8;

// public interface
// Public interface
export const Directions = {
RIGHT: RIGHT,
LEFT: LEFT,
UP: UP,
DOWN: DOWN,
} as const;

// internal interface
// Internal interface
export const DiagonalDirections = {
UP_RIGHT: UP | RIGHT,
DOWN_RIGHT: DOWN | RIGHT,
Expand Down
6 changes: 3 additions & 3 deletions src/components/DrawerLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

onGestureRef?: (ref: PanGestureHandler) => void;

// implicit `children` prop has been removed in @types/react^18.0.0
// Implicit `children` prop has been removed in @types/react^18.0.0
children?:
| React.ReactNode
| ((openValue?: AnimatedInterpolation) => React.ReactNode);
Expand Down Expand Up @@ -330,7 +330,7 @@
);

const dragOffsetFromOnStartPosition = startPositionX.interpolate({
inputRange: [drawerWidth! - 1, drawerWidth!, drawerWidth! + 1],

Check warning on line 333 in src/components/DrawerLayout.tsx

View workflow job for this annotation

GitHub Actions / check

Forbidden non-null assertion

Check warning on line 333 in src/components/DrawerLayout.tsx

View workflow job for this annotation

GitHub Actions / check

Forbidden non-null assertion

Check warning on line 333 in src/components/DrawerLayout.tsx

View workflow job for this annotation

GitHub Actions / check

Forbidden non-null assertion
outputRange: [0, 0, 1],
});
translationX = Animated.add(
Expand Down Expand Up @@ -519,7 +519,7 @@
this.emitStateChanged(IDLE, willShow);
this.setState({ drawerOpened: willShow });
if (this.state.drawerState !== DRAGGING) {
// it's possilbe that user started drag while the drawer
// It's possilbe that user started drag while the drawer
// was settling, don't override state in this case
this.setState({ drawerState: IDLE });
}
Expand Down Expand Up @@ -601,7 +601,7 @@
const drawerSlide = drawerType !== 'back';
const containerSlide = drawerType !== 'front';

// we rely on row and row-reverse flex directions to position the drawer
// We rely on row and row-reverse flex directions to position the drawer
// properly. Apparently for RTL these are flipped which requires us to use
// the opposite setting for the drawer to appear from left or right
// according to the drawerPosition prop
Expand Down
4 changes: 2 additions & 2 deletions src/components/GestureButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ class InnerBaseButton extends React.Component<BaseButtonWithRefProps> {
);
}
} else if (
// cancel longpress timeout if it's set and the finger moved out of the view
// Cancel longpress timeout if it's set and the finger moved out of the view
state === State.ACTIVE &&
!pointerInside &&
this.longPressTimeout !== undefined
) {
clearTimeout(this.longPressTimeout);
this.longPressTimeout = undefined;
} else if (
// cancel longpress timeout if it's set and the gesture has finished
// Cancel longpress timeout if it's set and the gesture has finished
this.longPressTimeout !== undefined &&
(state === State.END ||
state === State.CANCELLED ||
Expand Down
2 changes: 1 addition & 1 deletion src/components/GestureComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const ScrollView = React.forwardRef<
/>
);
});
// backward type compatibility with https://github.com/software-mansion/react-native-gesture-handler/blob/db78d3ca7d48e8ba57482d3fe9b0a15aa79d9932/react-native-gesture-handler.d.ts#L440-L457
// Backward type compatibility with https://github.com/software-mansion/react-native-gesture-handler/blob/db78d3ca7d48e8ba57482d3fe9b0a15aa79d9932/react-native-gesture-handler.d.ts#L440-L457
// include methods of wrapped components by creating an intersection type with the RN component instead of duplicating them.
// eslint-disable-next-line @typescript-eslint/no-redeclare
export type ScrollView = typeof GHScrollView & RNScrollView;
Expand Down
2 changes: 1 addition & 1 deletion src/components/GestureHandlerRootView.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function GestureHandlerRootView({
style,
...rest
}: GestureHandlerRootViewProps) {
// try initialize fabric on the first render, at this point we can
// Try initialize fabric on the first render, at this point we can
// reliably check if fabric is enabled (the function contains a flag
// to make sure it's called only once)
maybeInitializeFabric();
Expand Down
2 changes: 1 addition & 1 deletion src/components/GestureHandlerRootView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function GestureHandlerRootView({
style,
...rest
}: GestureHandlerRootViewProps) {
// try initialize fabric on the first render, at this point we can
// Try initialize fabric on the first render, at this point we can
// reliably check if fabric is enabled (the function contains a flag
// to make sure it's called only once)
maybeInitializeFabric();
Expand Down
6 changes: 3 additions & 3 deletions src/components/Pressable/Pressable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function Pressable(props: PressableProps) {

const pressableRef = useRef<View>(null);

// disabled when onLongPress has been called
// Disabled when onLongPress has been called
const isPressCallbackEnabled = useRef<boolean>(true);
const isPressedDown = useRef<boolean>(false);

Expand Down Expand Up @@ -107,7 +107,7 @@ export default function Pressable(props: PressableProps) {
}

if (props.unstable_pressDelay && pressDelayTimeoutRef.current !== null) {
// legacy Pressable behaviour - if pressDelay is set, we want to call onPressIn on touch up
// Legacy Pressable behaviour - if pressDelay is set, we want to call onPressIn on touch up
clearTimeout(pressDelayTimeoutRef.current);
pressInHandler(event);
}
Expand Down Expand Up @@ -228,7 +228,7 @@ export default function Pressable(props: PressableProps) {
}
}

// uses different hitSlop, to activate on hitSlop area instead of pressRetentionOffset area
// Uses different hitSlop, to activate on hitSlop area instead of pressRetentionOffset area
rippleGesture.hitSlop(normalizedHitSlop);

const gesture = Gesture.Simultaneous(
Expand Down
4 changes: 2 additions & 2 deletions src/components/Pressable/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const touchToPressEvent = (
pageY: data.absoluteY,
target: targetId,
timestamp: timestamp,
touches: [], // always empty - legacy compatibility
changedTouches: [], // always empty - legacy compatibility
touches: [], // Always empty - legacy compatibility
changedTouches: [], // Always empty - legacy compatibility
});

const changeToTouchData = (
Expand Down
6 changes: 3 additions & 3 deletions src/components/ReanimatedSwipeable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(

const progressTarget = toValue === 0 ? 0 : 1;

// velocity is in px, while progress is in %
// Velocity is in px, while progress is in %
springConfig.velocity = 0;

showLeftProgress.value =
Expand Down Expand Up @@ -510,12 +510,12 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
toValue = -rightWidth.value;
}
} else if (rowState.value === 1) {
// swiped to left
// Swiped to left
if (translationX > -leftThreshold) {
toValue = leftWidth.value;
}
} else {
// swiped to right
// Swiped to right
if (translationX < rightThreshold) {
toValue = -rightWidth.value;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Swipeable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ export default class Swipeable extends Component<
toValue = -rightWidth;
}
} else if (rowState === 1) {
// swiped to left
// Swiped to left
if (translationX > -leftThreshold) {
toValue = leftWidth;
}
} else {
// swiped to right
// Swiped to right
if (translationX < rightThreshold) {
toValue = -rightWidth;
}
Expand Down Expand Up @@ -509,7 +509,7 @@ export default class Swipeable extends Component<
<Animated.View
style={[
styles.leftActions,
// all those and below parameters can have ! since they are all
// All those and below parameters can have ! since they are all
// asigned in constructor in `updateAnimatedEvent` but TS cannot spot
// it for some reason
{ transform: [{ translateX: this.leftActionTranslate! }] },
Expand Down
10 changes: 5 additions & 5 deletions src/components/touchables/GenericTouchable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class GenericTouchable extends Component<
},
};

// timeout handlers
// Timeout handlers
pressInTimeout: Timeout;
pressOutTimeout: Timeout;
longPressTimeout: Timeout;
Expand Down Expand Up @@ -120,7 +120,7 @@ export default class GenericTouchable extends Component<
componentDidMount() {
this.reset();
}
// reset timeout to prevent memory leaks.
// Reset timeout to prevent memory leaks.
reset() {
this.longPressDetected = false;
this.pointerInside = true;
Expand Down Expand Up @@ -202,12 +202,12 @@ export default class GenericTouchable extends Component<

onLongPressDetected = () => {
this.longPressDetected = true;
// checked for in the caller of `onLongPressDetected`, but better to check twice
// Checked for in the caller of `onLongPressDetected`, but better to check twice
this.props.onLongPress?.();
};

componentWillUnmount() {
// to prevent memory leaks
// To prevent memory leaks
this.reset();
}

Expand All @@ -219,7 +219,7 @@ export default class GenericTouchable extends Component<
}

onMoveOut() {
// long press should no longer be detected
// Long press should no longer be detected
clearTimeout(this.longPressTimeout!);
this.longPressTimeout = null;
if (this.STATE === TOUCHABLE_STATE.BEGAN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class TouchableNativeFeedback extends Component<TouchableNativeFe
},
};

// could be taken as RNTouchableNativeFeedback.SelectableBackground etc. but the API may change
// Could be taken as RNTouchableNativeFeedback.SelectableBackground etc. but the API may change
static SelectableBackground = (rippleRadius?: number) => ({
type: 'ThemeAttrAndroid',
// I added `attribute` prop to clone the implementation of RN and be able to use only 2 types
Expand Down
2 changes: 1 addition & 1 deletion src/components/touchables/TouchableOpacity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class TouchableOpacity extends Component<TouchableOpacityProps> {
activeOpacity: 0.2,
};

// opacity is 1 one by default but could be overwritten
// Opacity is 1 one by default but could be overwritten
getChildStyleOpacityWithDefault = () => {
const childStyle = StyleSheet.flatten(this.props.style) || {};
return childStyle.opacity == null
Expand Down
4 changes: 2 additions & 2 deletions src/getShadowNodeFromRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let getInternalInstanceHandleFromPublicInstance: (ref: unknown) => {
};

export function getShadowNodeFromRef(ref: unknown) {
// load findHostInstance_DEPRECATED lazily because it may not be available before render
// Load findHostInstance_DEPRECATED lazily because it may not be available before render
if (findHostInstance_DEPRECATED === undefined) {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand All @@ -20,7 +20,7 @@ export function getShadowNodeFromRef(ref: unknown) {
}
}

// load findHostInstance_DEPRECATED lazily because it may not be available before render
// Load findHostInstance_DEPRECATED lazily because it may not be available before render
if (getInternalInstanceHandleFromPublicInstance === undefined) {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/createHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ if (UIManagerConstants) {
// Wrap JS responder calls and notify gesture handler manager
const {
setJSResponder: oldSetJSResponder = () => {
//no operation
// no-op
},
clearJSResponder: oldClearJSResponder = () => {
//no operation
// no-op
},
} = UIManagerAny;
UIManagerAny.setJSResponder = (tag: number, blockNativeResponder: boolean) => {
Expand Down Expand Up @@ -318,7 +318,7 @@ export default function createHandler<
this.viewTag = newViewTag;

if (Platform.OS === 'web') {
// typecast due to dynamic resolution, attachGestureHandler should have web version signature in this branch
// Typecast due to dynamic resolution, attachGestureHandler should have web version signature in this branch
(
RNGestureHandlerModule.attachGestureHandler as AttachGestureHandlerWeb
)(
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/createNativeWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function createNativeWrapper<P>(
React.ComponentType<any>,
P & NativeViewGestureHandlerProps
>((props, ref) => {
// filter out props that should be passed to gesture handler wrapper
// Filter out props that should be passed to gesture handler wrapper
const gestureHandlerProps = Object.keys(props).reduce(
(res, key) => {
// TS being overly protective with it's types, see https://github.com/microsoft/TypeScript/issues/26255#issuecomment-458013731 for more info
Expand All @@ -39,7 +39,7 @@ export default function createNativeWrapper<P>(
}
return res;
},
{ ...config } // watch out not to modify config
{ ...config } // Watch out not to modify config
);
const _ref = useRef<React.ComponentType<P>>();
const _gestureHandlerRef = useRef<React.ComponentType<P>>();
Expand All @@ -48,7 +48,7 @@ export default function createNativeWrapper<P>(
// @ts-ignore TODO(TS) decide how nulls work in this context
() => {
const node = _gestureHandlerRef.current;
// add handlerTag for relations config
// Add handlerTag for relations config
if (_ref.current && node) {
// @ts-ignore FIXME(TS) think about createHandler return type
_ref.current.handlerTag = node.handlerTag;
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/gestureHandlerCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export type TouchAction =
| 'revert-layer'
| 'unset';

//TODO(TS) events in handlers
// TODO(TS) events in handlers

export interface GestureEvent<ExtraEventPayloadT = Record<string, unknown>> {
nativeEvent: Readonly<GestureEventPayload & ExtraEventPayloadT>;
Expand Down Expand Up @@ -201,11 +201,11 @@ export type BaseGestureHandlerProps<
onActivated?: (event: HandlerStateChangeEvent) => void;
onEnded?: (event: HandlerStateChangeEvent) => void;

//TODO(TS) consider using NativeSyntheticEvent
// TODO(TS) consider using NativeSyntheticEvent
onGestureEvent?: (event: GestureEvent<ExtraEventPayloadT>) => void;
onHandlerStateChange?: (
event: HandlerStateChangeEvent<ExtraEventPayloadT>
) => void;
// implicit `children` prop has been removed in @types/react^18.0.0
// Implicit `children` prop has been removed in @types/react^18.0.0
children?: React.ReactNode;
};
8 changes: 4 additions & 4 deletions src/handlers/gestureHandlerTypesCompat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import type { RotationGestureHandlerProps } from './RotationGestureHandler';
import type { TapGestureHandlerProps } from './TapGestureHandler';
import type { NativeViewGestureHandlerProps } from './NativeViewGestureHandler';

// events
// Events
export type GestureHandlerGestureEventNativeEvent = GestureEventPayload;
export type GestureHandlerStateChangeNativeEvent =
HandlerStateChangeEventPayload;
export type GestureHandlerGestureEvent = GestureEvent;
export type GestureHandlerStateChangeEvent = HandlerStateChangeEvent;
// gesture handlers events
// Gesture handlers events
export type NativeViewGestureHandlerGestureEvent =
GestureEvent<NativeViewGestureHandlerPayload>;
export type NativeViewGestureHandlerStateChangeEvent =
Expand Down Expand Up @@ -76,7 +76,7 @@ export type FlingGestureHandlerGestureEvent =
export type FlingGestureHandlerStateChangeEvent =
HandlerStateChangeEvent<FlingGestureHandlerEventPayload>;

// handlers properties
// Handlers properties
export type NativeViewGestureHandlerProperties = NativeViewGestureHandlerProps;
export type TapGestureHandlerProperties = TapGestureHandlerProps;
export type LongPressGestureHandlerProperties = LongPressGestureHandlerProps;
Expand All @@ -85,7 +85,7 @@ export type PinchGestureHandlerProperties = PinchGestureHandlerProps;
export type RotationGestureHandlerProperties = RotationGestureHandlerProps;
export type FlingGestureHandlerProperties = FlingGestureHandlerProps;
export type ForceTouchGestureHandlerProperties = ForceTouchGestureHandlerProps;
// button props
// Button props
export type RawButtonProperties = RawButtonProps;
export type BaseButtonProperties = BaseButtonProps;
export type RectButtonProperties = RectButtonProps;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/gestures/GestureDetector/Wrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tagMessage } from '../../../utils';

export class Wrap extends React.Component<{
onGestureHandlerEvent?: unknown;
// implicit `children` prop has been removed in @types/react^18.0.0
// Implicit `children` prop has been removed in @types/react^18.0.0
children?: React.ReactNode;
}> {
render() {
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/gestures/GestureDetector/attachHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function attachHandlers({
}: AttachHandlersConfig) {
gestureConfig.initialize();

// use queueMicrotask to extract handlerTags, because all refs should be initialized
// Use queueMicrotask to extract handlerTags, because all refs should be initialized
// when it's ran
ghQueueMicrotask(() => {
if (!preparedGesture.isMounted) {
Expand All @@ -52,7 +52,7 @@ export function attachHandlers({
registerHandler(handler.handlerTag, handler, handler.config.testId);
}

// use queueMicrotask to extract handlerTags, because all refs should be initialized
// Use queueMicrotask to extract handlerTags, because all refs should be initialized
// when it's ran
ghQueueMicrotask(() => {
if (!preparedGesture.isMounted) {
Expand Down Expand Up @@ -83,7 +83,7 @@ export function attachHandlers({
)(
gesture.handlerTag,
viewTag,
ActionType.JS_FUNCTION_OLD_API, // ignored on web
ActionType.JS_FUNCTION_OLD_API, // Ignored on web
webEventHandlersRef
);
} else {
Expand Down
Loading
Loading