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

Add ts-prune #4772

Merged
merged 13 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions .github/workflows/static-root-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
cache: 'yarn'
- name: Clear annotations
run: scripts/clear-annotations.sh

- name: Install node dependencies
run: yarn
- name: Check types
Expand All @@ -36,7 +35,9 @@ jobs:
run: yarn type:check-api
- name: Lint
run: yarn lint:js
- name: Finding circular dependencies
- name: Find unused code
run: yarn find-unused-code:js
- name: Find circular dependencies
run: yarn circular_dependency_check
- name: Jest test:unit
- name: Run jest unit tests
run: yarn test:unit
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"format:ios": "find ios/ -iname *.h -o -iname *.m -o -iname *.mm -o -iname *.cpp | xargs clang-format -i --Werror",
"format:android": "find android/src/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
"format:common": "find Common/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
"find-unused-code:js": "yarn ts-prune --ignore \"index|.web.\" --error ",
"type:check": "yarn tsc --noEmit && cd plugin && yarn type:check && cd ..",
"type:check-api": "yarn tsc --noEmit --target es6 --module ESNext --jsx react-native --skipLibCheck true --allowSyntheticDefaultImports true --moduleResolution node --esModuleInterop true --strict true --forceConsistentCasingInFileNames true --resolveJsonModule true app/src/App.tsx",
"prepare": "yarn plugin && bob build && husky install && yarn app",
Expand Down Expand Up @@ -147,6 +148,7 @@
"react-native-web": "~0.18.12",
"react-test-renderer": "17.0.2",
"shelljs": "^0.8.5",
"ts-prune": "^0.10.3",
"typescript": "^4.1.3"
},
"lint-staged": {
Expand Down
4 changes: 2 additions & 2 deletions src/createAnimatedComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ interface AnimatedProps extends Record<string, unknown> {
initial?: SharedValue<StyleProps>;
}

export type AnimatedComponentProps<P extends Record<string, unknown>> = P & {
type AnimatedComponentProps<P extends Record<string, unknown>> = P & {
forwardedRef?: Ref<Component>;
style?: NestedArray<StyleProps>;
animatedProps?: Partial<AnimatedComponentProps<AnimatedProps>>;
Expand Down Expand Up @@ -247,7 +247,7 @@ interface ComponentRef extends Component {
getAnimatableRef?: () => ComponentRef;
}

export interface InitialComponentProps extends Record<string, unknown> {
interface InitialComponentProps extends Record<string, unknown> {
ref?: Ref<Component>;
collapsable?: boolean;
}
Expand Down
4 changes: 2 additions & 2 deletions src/reanimated2/UpdateProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ViewRefSet } from './ViewDescriptorsSet';
import { runOnUIImmediately } from './threads';

// copied from react-native/Libraries/Components/View/ReactNativeStyleAttributes
export const colorProps = [
const colorProps = [
'backgroundColor',
'borderBottomColor',
'borderColor',
Expand All @@ -33,7 +33,7 @@ export const colorProps = [

export const ColorProperties = makeShareable(colorProps);

export let updateProps: (
let updateProps: (
viewDescriptor: SharedValue<Descriptor[]>,
updates: StyleProps | AnimatedStyle,
maybeViewRef: ViewRefSet<any> | undefined
Expand Down
15 changes: 0 additions & 15 deletions src/reanimated2/__mocks__/MutableValue.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/reanimated2/__mocks__/NativeReanimated.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/reanimated2/animation/decay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface DecayAnimation extends Animation<DecayAnimation> {
current: AnimatableValue;
}

export interface InnerDecayAnimation
interface InnerDecayAnimation
extends Omit<DecayAnimation, 'current'>,
AnimationObject {
current: number;
Expand Down
4 changes: 2 additions & 2 deletions src/reanimated2/animation/styleAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { processColor } from '../Colors';

// resolves path to value for nested objects
// if path cannot be resolved returns undefined
export function resolvePath<T>(
function resolvePath<T>(
obj: NestedObject<T>,
path: AnimatableValue[] | AnimatableValue
): NestedObjectValues<T> | undefined {
Expand All @@ -39,7 +39,7 @@ export function resolvePath<T>(

// set value at given path
type Path = Array<string | number> | string | number;
export function setPath<T>(
function setPath<T>(
obj: NestedObject<T>,
path: Path,
value: NestedObjectValues<T>
Expand Down
2 changes: 1 addition & 1 deletion src/reanimated2/animation/timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface TimingAnimation extends Animation<TimingAnimation> {
current: AnimatableValue;
}

export interface InnerTimingAnimation
interface InnerTimingAnimation
extends Omit<TimingAnimation, 'toValue' | 'current'> {
toValue: number;
current: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type AffineMatrix = FixedLengthArray<FixedLengthArray<number, 4>, 4>;

export type AffineMatrixFlat = FixedLengthArray<number, 16>;

export type TransformMatrixDecomposition = Record<
type TransformMatrixDecomposition = Record<
'translationMatrix' | 'scaleMatrix' | 'rotationMatrix' | 'skewMatrix',
AffineMatrix
>;
Expand Down
26 changes: 1 addition & 25 deletions src/reanimated2/animation/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import type {
HigherOrderAnimation,
NextAnimation,
StyleLayoutAnimation,
} from './commonTypes';
import type { HigherOrderAnimation, StyleLayoutAnimation } from './commonTypes';
import type { ParsedColorArray } from '../Colors';
import {
isColor,
Expand All @@ -11,9 +7,7 @@ import {
toGammaSpace,
toLinearSpace,
} from '../Colors';

import type {
AnimatedStyle,
SharedValue,
AnimatableValue,
Animation,
Expand All @@ -37,8 +31,6 @@ import {

let IN_STYLE_UPDATER = false;

export type UserUpdater = () => AnimatedStyle;

export function initialUpdaterRun<T>(updater: () => T): T {
IN_STYLE_UPDATER = true;
const result = updater();
Expand Down Expand Up @@ -449,19 +441,3 @@ export function cancelAnimation<T>(sharedValue: SharedValue<T>): void {
// setting the current value cancels the animation if one is currently running
sharedValue.value = sharedValue.value; // eslint-disable-line no-self-assign
}

// TODO it should work only if there was no animation before.
export function withStartValue(
startValue: AnimatableValue,
animation: NextAnimation<AnimationObject>
): Animation<AnimationObject> {
'worklet';
return defineAnimation(startValue, () => {
'worklet';
if (!_WORKLET && typeof animation === 'function') {
animation = animation();
}
(animation as Animation<AnimationObject>).current = startValue;
return animation as Animation<AnimationObject>;
});
}
2 changes: 1 addition & 1 deletion src/reanimated2/component/FlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ declare class ReanimatedFlatListClass<T> extends Component<
getNode(): FlatList;
}

export interface ReanimatedFlatListProps<ItemT> extends FlatListProps<ItemT> {
interface ReanimatedFlatListProps<ItemT> extends FlatListProps<ItemT> {
itemLayoutAnimation?: ILayoutAnimationBuilder;
}

Expand Down
1 change: 1 addition & 0 deletions src/reanimated2/helperTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export type AnimateProps<P extends object> = NonStyleAnimatedProps<P> &
animatedProps?: Partial<AnimatedPropsProp<P>>;
};

// ts-prune-ignore-next This will be used soon
export type AnimatedProps<P extends object> = AnimateProps<P>;
tjzel marked this conversation as resolved.
Show resolved Hide resolved

export type AnimatedPropsAdapterFunction = (
Expand Down
4 changes: 2 additions & 2 deletions src/reanimated2/hook/useAnimatedGestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface GestureHandlers<T, TContext extends Context> {
onFinish?: Handler<T, TContext>;
}

export const EventType = {
const EventType = {
UNDETERMINED: 0,
FAILED: 1,
BEGAN: 2,
Expand All @@ -25,7 +25,7 @@ export const EventType = {
END: 5,
};

export interface GestureHandlerNativeEvent {
interface GestureHandlerNativeEvent {
handlerTag: number;
numberOfPointers: number;
state: (typeof EventType)[keyof typeof EventType];
Expand Down
32 changes: 3 additions & 29 deletions src/reanimated2/hook/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { MutableRefObject } from 'react';
import { useEffect, useRef } from 'react';
import { processColor } from '../Colors';
import type {
AnimatedStyle,
Context,
Expand All @@ -11,7 +10,6 @@ import type {
} from '../commonTypes';
import { makeRemote } from '../core';
import { isWeb, isJest } from '../PlatformChecker';
import { colorProps } from '../UpdateProps';
import WorkletEventHandler from '../WorkletEventHandler';
import type { ContextWithDependencies, DependencyList } from './commonTypes';
import type { NativeSyntheticEvent } from 'react-native';
Expand All @@ -23,7 +21,7 @@ interface Handlers<T, TContext extends Context> {
[key: string]: Handler<T, TContext> | undefined;
}

export interface UseHandlerContext<TContext extends Context> {
interface UseHandlerContext<TContext extends Context> {
context: TContext;
doDependenciesDiffer: boolean;
useWeb: boolean;
Expand Down Expand Up @@ -104,7 +102,7 @@ export function buildWorkletsHash(
}

// builds dependencies array for gesture handlers
export function buildDependencies(
function buildDependencies(
dependencies: DependencyList,
handlers: Record<string, WorkletFunction | undefined>
): Array<unknown> {
Expand All @@ -126,7 +124,7 @@ export function buildDependencies(
}

// this is supposed to work as useEffect comparison
export function areDependenciesEqual(
function areDependenciesEqual(
nextDeps: DependencyList,
prevDeps: DependencyList
): boolean {
Expand Down Expand Up @@ -156,30 +154,6 @@ export function areDependenciesEqual(
return areHookInputsEqual(nextDeps, prevDeps);
}

export function hasColorProps(updates: AnimatedStyle): boolean {
const colorPropsSet = new Set(colorProps);
for (const key in updates) {
if (colorPropsSet.has(key)) {
return true;
}
}
return false;
}

export function parseColors(updates: AnimatedStyle): void {
'worklet';
for (const key in updates) {
if (colorProps.indexOf(key) !== -1) {
// value could be an animation in which case processColor will recognize it and will return undefined
// -> in such a case we don't want to override style of that key
const processedColor = processColor(updates[key]);
if (processedColor !== undefined) {
updates[key] = processedColor;
}
}
}
}

export function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {
'worklet';
if (Array.isArray(prop)) {
Expand Down
Loading