Skip to content

Commit

Permalink
Fix lint errors (#2698)
Browse files Browse the repository at this point in the history
* Format Snapshot.java

* Migrate to new layout animation prop names

* Fix TypeScript errors
  • Loading branch information
tomekzaw authored Dec 8, 2021
1 parent 3b27846 commit de26314
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 42 deletions.
10 changes: 8 additions & 2 deletions Example/src/LayoutReanimation/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import Animated, {
useAnimatedStyle,
withTiming,
EntryExitAnimationFunction,
EntryAnimationsValues,
ExitAnimationsValues,
} from 'react-native-reanimated';

function AnimatedView() {
const style = useAnimatedStyle(() => {
return {};
});

const entering: EntryExitAnimationFunction = (targetValues) => {
const entering: EntryExitAnimationFunction = (
targetValues: EntryAnimationsValues
) => {
'worklet';

return {
Expand All @@ -36,7 +40,9 @@ function AnimatedView() {
};
};

const exiting: EntryExitAnimationFunction = (targetValues) => {
const exiting: EntryExitAnimationFunction = (
targetValues: ExitAnimationsValues
) => {
'worklet';

return {
Expand Down
10 changes: 8 additions & 2 deletions Example/src/LayoutReanimation/ModalNewAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import Animated, {
withDelay,
EntryExitAnimationFunction,
Layout,
EntryAnimationsValues,
ExitAnimationsValues,
} from 'react-native-reanimated';

const { width } = Dimensions.get('window');

function AnimatedView() {
const ref = useRef(null);
const entering: EntryExitAnimationFunction = (targetValues) => {
const entering: EntryExitAnimationFunction = (
targetValues: EntryAnimationsValues
) => {
'worklet';
const animations = {
originX: withTiming(targetValues.targetOriginX, { duration: 3000 }),
Expand All @@ -34,7 +38,9 @@ function AnimatedView() {
};
};

const exiting: EntryExitAnimationFunction = (startingValues) => {
const exiting: EntryExitAnimationFunction = (
startingValues: ExitAnimationsValues
) => {
'worklet';
const animations = {
originX: withTiming(width, { duration: 3000 }),
Expand Down
16 changes: 8 additions & 8 deletions Example/test/CustomLayout2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ function CustomLayoutTransiton(): LayoutAnimationFunction {
animations: {
originX: withDelay(
isEvenLocal ? 1000 : 0,
withTiming(values.originX, { duration: 1000 })
withTiming(values.targetOriginX, { duration: 1000 })
),
originY: withDelay(
isEvenLocal ? 0 : 1000,
withTiming(values.originY, { duration: 1000 })
withTiming(values.targetOriginY, { duration: 1000 })
),
width: withTiming(values.width, { duration: 1000 }),
height: withTiming(values.height, { duration: 1000 }),
width: withTiming(values.targetWidth, { duration: 1000 }),
height: withTiming(values.targetHeight, { duration: 1000 }),
},
initialValues: {
originX: values.boriginX,
originY: values.boriginY,
width: values.bwidth,
height: values.bheight,
originX: values.currentOriginX,
originY: values.currentOriginY,
width: values.currentWidth,
height: values.currentHeight,
},
};
};
Expand Down
16 changes: 8 additions & 8 deletions Example/test/CustomLayout3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ function CustomLayoutTransiton(): LayoutAnimationFunction {
animations: {
originX: withDelay(
isEvenLocal ? 1000 : 0,
withTiming(values.originX, { duration: 1000 })
withTiming(values.targetOriginX, { duration: 1000 })
),
originY: withDelay(
isEvenLocal ? 0 : 1000,
withTiming(values.originY, { duration: 1000 })
withTiming(values.targetOriginY, { duration: 1000 })
),
width: withTiming(values.width, { duration: 1000 }),
height: withTiming(values.height, { duration: 1000 }),
width: withTiming(values.targetWidth, { duration: 1000 }),
height: withTiming(values.targetHeight, { duration: 1000 }),
},
initialValues: {
originX: values.boriginX,
originY: values.boriginY,
width: values.bwidth,
height: values.bheight,
originX: values.currentOriginX,
originY: values.currentOriginY,
width: values.currentWidth,
height: values.currentHeight,
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.facebook.react.uimanager.IllegalViewOperationException;
import com.facebook.react.uimanager.NativeViewHierarchyManager;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -64,24 +63,24 @@ public class Snapshot {
globalOriginX = location[0];
globalOriginY = location[1];

targetKeysToTransform = new ArrayList<>(
Arrays.asList(
Snapshot.TARGET_WIDTH,
Snapshot.TARGET_HEIGHT,
Snapshot.TARGET_ORIGIN_X,
Snapshot.TARGET_ORIGIN_Y,
Snapshot.TARGET_GLOBAL_ORIGIN_X,
Snapshot.TARGET_GLOBAL_ORIGIN_Y)
);
currentKeysToTransform = new ArrayList<>(
Arrays.asList(
Snapshot.CURRENT_WIDTH,
Snapshot.CURRENT_HEIGHT,
Snapshot.CURRENT_ORIGIN_X,
Snapshot.CURRENT_ORIGIN_Y,
Snapshot.CURRENT_GLOBAL_ORIGIN_X,
Snapshot.CURRENT_GLOBAL_ORIGIN_Y)
);
targetKeysToTransform =
new ArrayList<>(
Arrays.asList(
Snapshot.TARGET_WIDTH,
Snapshot.TARGET_HEIGHT,
Snapshot.TARGET_ORIGIN_X,
Snapshot.TARGET_ORIGIN_Y,
Snapshot.TARGET_GLOBAL_ORIGIN_X,
Snapshot.TARGET_GLOBAL_ORIGIN_Y));
currentKeysToTransform =
new ArrayList<>(
Arrays.asList(
Snapshot.CURRENT_WIDTH,
Snapshot.CURRENT_HEIGHT,
Snapshot.CURRENT_ORIGIN_X,
Snapshot.CURRENT_ORIGIN_Y,
Snapshot.CURRENT_GLOBAL_ORIGIN_X,
Snapshot.CURRENT_GLOBAL_ORIGIN_Y));
}

private void addTargetConfig(HashMap<String, Object> data) {
Expand Down
22 changes: 19 additions & 3 deletions react-native-reanimated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,25 @@ declare module 'react-native-reanimated' {
currentGlobalOriginY: number;
}

export type EntryExitAnimationFunction = (
targetValues: EntryAnimationsValues | ExitAnimationsValues
) => LayoutAnimation;
export interface EntryExitAnimationsValues {
targetOriginX?: number;
targetOriginY?: number;
targetWidth?: number;
targetHeight?: number;
targetGlobalOriginX?: number;
targetGlobalOriginY?: number;
currentOriginX?: number;
currentOriginY?: number;
Ŕ;
currentWidth?: number;
currentHeight?: number;
currentGlobalOriginX?: number;
currentGlobalOriginY?: number;
}

export type EntryExitAnimationFunction =
| ((targetValues: EntryAnimationsValues) => LayoutAnimation)
| ((targetValues: ExitAnimationsValues) => LayoutAnimation);

export type LayoutAnimationsValues = {
currentOriginX: number;
Expand Down

0 comments on commit de26314

Please sign in to comment.