Skip to content

Commit

Permalink
Fix exporting enums as types and type of global in PlatformChecker (#…
Browse files Browse the repository at this point in the history
…5105)

<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

Fixes regression that occurred in #5074.

Later on we also have to rethink if we want to promote `Extrapolate` or
`Extrapolation` since both are exactly the same and we only use the
former.

## Test plan

I actually made `Extrapolation` used in our examples so such mistake in
the future would be caught on CI (only regarding `Extrapolation` sadly).

> [!Note]
> I recommend using this
> ```json
> "editor.tokenColorCustomizations": {
>    "textMateRules": [
>      {
>        "scope": "entity.name.type.enum",
>        "settings": {
>          "foreground": "#a3e577"
>        }
>      },
>      {
>        "scope": "entity.name.type.class",
>        "settings": {
>          "foreground": "#e8b55e"
>        }
>      }
>    ]
>  }
>```
> In your VSCode settings so Classes, Enums and Types are not in the
same color.
  • Loading branch information
tjzel authored Sep 21, 2023
1 parent d77be14 commit 265ebf5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app/src/examples/DragAndSnapExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Animated, {
useAnimatedStyle,
useAnimatedGestureHandler,
interpolate,
Extrapolate,
Extrapolation,
} from 'react-native-reanimated';
import {
PanGestureHandler,
Expand Down Expand Up @@ -42,10 +42,10 @@ export default function DragAndSnapExample() {

const stylez = useAnimatedStyle(() => {
const H = Math.round(
interpolate(translation.x.value, [0, 300], [0, 360], Extrapolate.CLAMP)
interpolate(translation.x.value, [0, 300], [0, 360], Extrapolation.CLAMP)
);
const S = Math.round(
interpolate(translation.y.value, [0, 500], [100, 50], Extrapolate.CLAMP)
interpolate(translation.y.value, [0, 500], [100, 50], Extrapolation.CLAMP)
);
const backgroundColor = `hsl(${H},${S}%,50%)`;
return {
Expand Down
15 changes: 12 additions & 3 deletions src/reanimated2/PlatformChecker.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
'use strict';
import { Platform } from 'react-native';

// This type is necessary since some libraries tend to do a lib check
// and this file causes type errors on `global` access.
type localGlobal = typeof global & Record<string, unknown>;

export function isJest(): boolean {
return !!process.env.JEST_WORKER_ID;
}

export function isChromeDebugger(): boolean {
return !(global as any).nativeCallSyncHook || (global as any).__REMOTEDEV__;
return (
!(global as localGlobal).nativeCallSyncHook ||
!!(global as localGlobal).__REMOTEDEV__
);
}

export function isWeb(): boolean {
Expand All @@ -33,13 +40,15 @@ export function isWindowAvailable() {
// the window object is unavailable when building the server portion of a site that uses SSG
// this function shouldn't be used to conditionally render components
// https://www.joshwcomeau.com/react/the-perils-of-rehydration/
// @ts-ignore Fallback if `window` is undefined.
return typeof window !== 'undefined';
}

export function isReducedMotion() {
return isWeb()
? isWindowAvailable()
? !window.matchMedia('(prefers-reduced-motion: no-preference)').matches
? // @ts-ignore Fallback if `window` is undefined.
!window.matchMedia('(prefers-reduced-motion: no-preference)').matches
: false
: global._REANIMATED_IS_REDUCED_MOTION ?? false;
: (global as localGlobal)._REANIMATED_IS_REDUCED_MOTION ?? false;
}
4 changes: 2 additions & 2 deletions src/reanimated2/hook/useAnimatedScrollHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface ScrollHandlers<TContext extends __Context> {
type OnScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => void;

// TODO TYPESCRIPT This is a temporary type to get rid of .d.ts file.
export type useAnimatedScrollHandler = <
type useAnimatedScrollHandlerType = <
TContext extends __Context = Record<string, never>
>(
handlers: ScrollHandlers<TContext> | ScrollHandler<TContext>,
Expand Down Expand Up @@ -101,4 +101,4 @@ export const useAnimatedScrollHandler = function <TContext extends __Context>(
// TODO TYPESCRIPT This temporary cast is to get rid of .d.ts file.
) as any;
// TODO TYPESCRIPT This temporary cast is to get rid of .d.ts file.
} as unknown as useAnimatedScrollHandler;
} as unknown as useAnimatedScrollHandlerType;
10 changes: 3 additions & 7 deletions src/reanimated2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,17 @@ export {
withRepeat,
withSequence,
} from './animation';
export type {
Extrapolation,
ExtrapolationConfig,
ExtrapolationType,
} from './interpolation';
export { interpolate, clamp } from './interpolation';
export type { ExtrapolationConfig, ExtrapolationType } from './interpolation';
export { Extrapolation, interpolate, clamp } from './interpolation';
export type {
InterpolationOptions,
ColorSpace,
InterpolateConfig,
InterpolateRGB,
InterpolateHSV,
} from './interpolateColor';
export {
Extrapolate,
ColorSpace,
interpolateColor,
useInterpolateConfig,
} from './interpolateColor';
Expand Down

0 comments on commit 265ebf5

Please sign in to comment.