Skip to content

Commit

Permalink
Merge pull request #3 from yekta/master
Browse files Browse the repository at this point in the history
Use Easing.out on closeAnimation
  • Loading branch information
iway1 authored Aug 30, 2022
2 parents 10b73d2 + 872f73a commit fa735d8
Showing 1 changed file with 44 additions and 36 deletions.
80 changes: 44 additions & 36 deletions package/src/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,59 @@
import { TextInput } from "react-native"
import Animated, { Easing } from "react-native-reanimated";
import {TextInput} from 'react-native';
import Animated, {Easing} from 'react-native-reanimated';

export async function measureFocusedInputBottomYAsync() {
return new Promise<number>(resolve=>{
const input = TextInput.State.currentlyFocusedInput();
if(!input) return;
input.measure((x, y, width, height, pageX, pageY)=>{
resolve(pageY + height);
})
})
return new Promise<number>(resolve => {
const input = TextInput.State.currentlyFocusedInput();
if (!input) return;
input.measure((x, y, width, height, pageX, pageY) => {
resolve(pageY + height);
});
});
}

export function measureFocusedInputBottomY(callback: (bottomY: number)=>void) {
const input = TextInput.State.currentlyFocusedInput();
if(!input) return;
input.measure((x, y, width, height, pageX, pageY)=>{
callback(pageY + height);
})
export function measureFocusedInputBottomY(
callback: (bottomY: number) => void,
) {
const input = TextInput.State.currentlyFocusedInput();
if (!input) return;
input.measure((x, y, width, height, pageX, pageY) => {
callback(pageY + height);
});
}

export function measureInputBottomYAsync() {
return new Promise<number>(resolve=>{
measureFocusedInputBottomY(resolve)
})
return new Promise<number>(resolve => {
measureFocusedInputBottomY(resolve);
});
}

export function calcAndroidSystemPan({
keyboardEndY,
inputBottomY,
} : {
keyboardEndY: number,
inputBottomY: number
keyboardEndY,
inputBottomY,
}: {
keyboardEndY: number;
inputBottomY: number;
}) {
const delta = inputBottomY - keyboardEndY;
return Math.max(0, delta);
const delta = inputBottomY - keyboardEndY;
return Math.max(0, delta);
}

export function closeAnimation(duration: number, easing: Animated.EasingFunction) {
return {
duration: duration + 50,
easing: Easing.in(easing)
}
export function closeAnimation(
duration: number,
easing: Animated.EasingFunction,
) {
return {
duration: duration + 50,
easing: Easing.out(easing),
};
}

export function openAnimation(duration: number, easing: Animated.EasingFunction) {
return {
duration,
easing: Easing.out(easing)
}
}
export function openAnimation(
duration: number,
easing: Animated.EasingFunction,
) {
return {
duration,
easing: Easing.out(easing),
};
}

0 comments on commit fa735d8

Please sign in to comment.