75 lines
3.5 KiB
TypeScript
75 lines
3.5 KiB
TypeScript
// Metro module 15587 (f15588).
|
|
import { useId, useLayoutEffect, useMemo } from "react";
|
|
import subscribeToKeyboardUIStore from "./subscribeToKeyboardUIStore";
|
|
import { TransitionStates, TransitionGroup } from "../../../design/components/TransitionGroup/TransitionGroup";
|
|
import { getKeyboardType } from "./useKeyboardType";
|
|
import { KeyboardTypes } from "./KeyboardTypes";
|
|
import { isAndroid } from "../../../utils/PlatformUtils";
|
|
import PortalKeyboardRendererComponent from "./PortalKeyboardRendererComponent";
|
|
import { registerPortalKeyboardRenderer, PortalKeyboardUIStore, closePortalKeyboardIfUnhandled } from "./PortalKeyboardUIStore.native";
|
|
import { getRootNavigationRef } from "../../main_tabs_v2/RootNavigationRef.native";
|
|
import { FAKE_PLACEHOLDER_PRIVATE_CHANNEL_ID } from "../../channel/FakePlaceholderPrivateChannel";
|
|
import { getFocusedChannelId } from "../../panels/isChannelFocused.native";
|
|
import { setKeyboardType } from "./KeyboardUIStore.native";
|
|
import { PortalKeyboard } from "./PortalKeyboard";
|
|
import { PortalKeyboardInModalContext } from "./PortalKeyboardModalContext";
|
|
let c11112_6, transitionGroupRenderItem;
|
|
const transitionGroupGetItemKey = function transitionGroupGetItemKey(a0) {
|
|
return a0.id;
|
|
};
|
|
c11112_6 = [];
|
|
transitionGroupRenderItem = (a0, a1, a2, a3) => a2 === TransitionStates.YEETED && getKeyboardType() === KeyboardTypes.SYSTEM && isAndroid() ? null : <PortalKeyboardRendererComponent key={a0} item={a1} state={a2} cleanUp={a3} />;
|
|
export function PortalKeyboardRenderer(props) {
|
|
let portal = props.portal;
|
|
if (portal === void 0) {
|
|
portal = true;
|
|
}
|
|
let field, c22217_2;
|
|
field = void 0;
|
|
c22217_2 = void 0;
|
|
const id = useId();
|
|
useLayoutEffect(() => registerPortalKeyboardRenderer(id), [id]);
|
|
useLayoutEffect(() => {
|
|
let c28090_0 = subscribeToKeyboardUIStore(function() {
|
|
const field2 = PortalKeyboardUIStore.getField("keyboard");
|
|
const keyboardType = getKeyboardType();
|
|
if (field2 != null && keyboardType !== field2.type) {
|
|
closePortalKeyboardIfUnhandled();
|
|
}
|
|
});
|
|
return () => {
|
|
c28090_0();
|
|
closePortalKeyboardIfUnhandled();
|
|
};
|
|
}, []);
|
|
useLayoutEffect(() => {
|
|
let rootNavigationRef;
|
|
const onNavigationStateChange2 = function onNavigationStateChange() {
|
|
const field2 = PortalKeyboardUIStore.getField("keyboard");
|
|
if (field2 != null && field2.channelId !== FAKE_PLACEHOLDER_PRIVATE_CHANNEL_ID && getFocusedChannelId() !== field2.channelId) {
|
|
if (getKeyboardType() !== KeyboardTypes.SYSTEM) {
|
|
setKeyboardType({
|
|
type: KeyboardTypes.SYSTEM
|
|
});
|
|
}
|
|
closePortalKeyboardIfUnhandled();
|
|
}
|
|
};
|
|
if (isAndroid()) {
|
|
rootNavigationRef = getRootNavigationRef();
|
|
if (rootNavigationRef != null) {
|
|
rootNavigationRef.addListener("state", onNavigationStateChange2);
|
|
return () => {
|
|
rootNavigationRef.removeListener("state", onNavigationStateChange2);
|
|
};
|
|
}
|
|
}
|
|
}, []);
|
|
field = PortalKeyboardUIStore.useField("keyboard");
|
|
const field2 = PortalKeyboardUIStore.useField("renderers");
|
|
const r2 = field2.length === 0 || field2[field2.length - 1] === id;
|
|
c22217_2 = r2;
|
|
const r53 = <TransitionGroup items={useMemo(() => field != null && c22217_2 ? [field] : c11112_6, [r2, field])} getItemKey={transitionGroupGetItemKey} renderItem={transitionGroupRenderItem} />;
|
|
return portal ? <PortalKeyboard>{r53}</PortalKeyboard> : <PortalKeyboardInModalContext.Provider value>{r53}</PortalKeyboardInModalContext.Provider>;
|
|
}
|