82 lines
3.2 KiB
TypeScript
82 lines
3.2 KiB
TypeScript
// Metro module 5215 (f5216).
|
|
import { useCallback, useRef, useState, useEffect } from "react";
|
|
import subscribeToKeyboardUIStore from "../keyboard/native/subscribeToKeyboardUIStore";
|
|
import { getKeyboardDuration } from "../keyboard/native/useKeyboardDuration";
|
|
import { DeprecatedLayoutAnimationKeyboard } from "../animations/native/DeprecatedLayoutAnimation";
|
|
import useSafeAreaInsets_native from "./useSafeAreaInsets.native";
|
|
import { useAppEntryKey } from "../window/native/AppEntryKeyContext";
|
|
import * as _PlatformUtils from "../../utils/PlatformUtils";
|
|
import { isIOS } from "../../utils/PlatformUtils";
|
|
import { getSystemKeyboardHeight } from "../keyboard/native/useSystemKeyboardHeight.native";
|
|
import { getKeyboardType } from "../keyboard/native/useKeyboardType";
|
|
import { KeyboardTypes } from "../keyboard/native/KeyboardTypes";
|
|
import { getCustomKeyboardHeight } from "../keyboard/native/useCustomKeyboardHeight";
|
|
export default function useSafeAreaInsetsKeyboardAware(r3 = {}) {
|
|
let isKeyboardAwareOnIOS = r3.isKeyboardAwareOnIOS;
|
|
if (isKeyboardAwareOnIOS === void 0) {
|
|
isKeyboardAwareOnIOS = true;
|
|
}
|
|
let ref, setState;
|
|
let c14762_0 = isKeyboardAwareOnIOS;
|
|
let isKeyboardAwareOnAndroid = r3.isKeyboardAwareOnAndroid;
|
|
if (isKeyboardAwareOnAndroid === void 0) {
|
|
isKeyboardAwareOnAndroid = true;
|
|
}
|
|
let c14762_1 = isKeyboardAwareOnAndroid;
|
|
let includeCustomKeyboardHeight = r3.includeCustomKeyboardHeight;
|
|
if (includeCustomKeyboardHeight === void 0) {
|
|
includeCustomKeyboardHeight = true;
|
|
}
|
|
let c14762_2 = includeCustomKeyboardHeight;
|
|
let includeKeyboardHeight = r3.includeKeyboardHeight;
|
|
if (includeKeyboardHeight === void 0) {
|
|
includeKeyboardHeight = false;
|
|
}
|
|
ref = void 0;
|
|
setState = void 0;
|
|
const safeAreaInsets_native = useSafeAreaInsets_native();
|
|
const appEntryKey = useAppEntryKey();
|
|
const callback = useCallback(() => {
|
|
if (isIOS() && !c14762_0) {
|
|
return 0;
|
|
}
|
|
if (_PlatformUtils.isAndroid() && !c14762_1) {
|
|
return 0;
|
|
}
|
|
let r23 = getSystemKeyboardHeight({
|
|
appEntryKey
|
|
});
|
|
if (r23 === 0) {
|
|
r23 = getKeyboardType(appEntryKey) !== KeyboardTypes.SYSTEM ? c14762_2 ? getCustomKeyboardHeight(appEntryKey) : 0 : 0;
|
|
}
|
|
return r23;
|
|
}, [appEntryKey, includeCustomKeyboardHeight, isKeyboardAwareOnIOS, isKeyboardAwareOnAndroid]);
|
|
ref = useRef(callback());
|
|
let state;
|
|
[state, setState] = useState(ref.current);
|
|
useEffect(() => subscribeToKeyboardUIStore(function() {
|
|
const current = callback();
|
|
if (ref.current !== current) {
|
|
ref.current = current;
|
|
setState(current);
|
|
}
|
|
}), [callback, isKeyboardAwareOnIOS, isKeyboardAwareOnAndroid]);
|
|
const isAndroid = (isKeyboardAwareOnIOS ? !includeKeyboardHeight : !isKeyboardAwareOnIOS) || _PlatformUtils.isAndroid();
|
|
const ref2 = useRef(false);
|
|
useEffect(() => {
|
|
const keyboardDuration = getKeyboardDuration();
|
|
if (ref2.current && (keyboardDuration !== 0 && !isAndroid)) {
|
|
DeprecatedLayoutAnimationKeyboard(keyboardDuration);
|
|
} else {
|
|
ref2.current = true;
|
|
}
|
|
}, [state, isAndroid]);
|
|
const bottom = includeKeyboardHeight ? state : 0;
|
|
return {
|
|
insets: state > 0 ? {
|
|
...safeAreaInsets_native,
|
|
bottom
|
|
} : safeAreaInsets_native
|
|
};
|
|
};
|