Files
discord-decomp/_bundle/KeyboardAvoidingView.jsx
T
2026-11-01 12:12:55 +02:00

249 lines
7.5 KiB
React

// Metro module 341 (f342).
import _objectWithoutProperties from "./_objectWithoutProperties";
import _classCallCheck from "./_classCallCheck";
import _createClass from "./_createClass";
import _possibleConstructorReturn from "./_possibleConstructorReturn";
import _getPrototypeOf from "./_getPrototypeOf";
import _inherits from "./_inherits";
import { Component, createRef } from "react";
import Module342 from "./Module342";
import KeyboardImpl from "./KeyboardImpl";
import View from "./View";
import Module254 from "./Module254";
let _excluded;
let KeyboardAvoidingView, c356_1;
let env355 = {};
env355[10] = function _isNativeReflectConstruct() {
let c12255_0;
try {
c12255_0 = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
} catch ($e) {}
const _isNativeReflectConstruct2 = function _isNativeReflectConstruct() {
return !!c12255_0;
};
env355[10] = _isNativeReflectConstruct2;
return _isNativeReflectConstruct2();
};
_excluded = ["behavior", "children", "contentContainerStyle", "enabled", "keyboardVerticalOffset", "style", "onLayout"];
c356_1 = void 0;
KeyboardAvoidingView = function KeyboardAvoidingView(a0) {
const r4 = env355;
_classCallCheck(this, KeyboardAvoidingView);
const r11 = [a0];
const r10 = _getPrototypeOf(KeyboardAvoidingView);
const r19 = (0, env355[10])() ? Reflect.construct(r10, r11, _getPrototypeOf(this).constructor) : r10.apply(this, r11);
let c23669_0;
let env23668 = {
$parent: r4
};
const r24 = _possibleConstructorReturn(this, r19);
env23668[0] = r24;
r24._frame = null;
r24._keyboardEvent = null;
r24._subscriptions = [];
r24._initialFrameHeight = 0;
r24._bottom = 0;
r24._onKeyboardChange = (a0) => {
const r2 = env23668[0];
r2._keyboardEvent = a0;
r2._updateBottomIfNecessary();
};
r24._onKeyboardHide = (a0) => {
const r2 = env23668[0];
r2._keyboardEvent = null;
r2._updateBottomIfNecessary();
};
c23669_0 = void 0;
c23669_0 = async (c31147_0) => {
let c31147_2;
let c31849_0;
L20: {
c31147_2 = void 0;
c31849_0 = c31147_0;
c31147_0.persist();
const _frame = env23668[0]._frame;
env23668[0]._frame = c31147_0.nativeEvent.layout;
if (!env23668[0]._initialFrameHeight) {
env23668[0]._initialFrameHeight = env23668[0]._frame.height;
}
if (_frame && _frame.height === env23668[0]._frame.height) {
if (!env23668[0].props.onLayout) {
break L20;
}
env23668[0].props.onLayout(c31849_0);
break L20;
}
await env23668[0]._updateBottomIfNecessary();
if (env23668[0].props.onLayout) {
env23668[0].props.onLayout(c31849_0);
}
return void 0;
}
};
r24._onLayout = function(a0) {
return c23669_0.apply(this, arguments);
};
r24._setBottom = (a0) => {
const r3 = env23668[0];
let enabled2 = r3.props.enabled;
if (enabled2 == null) {
enabled2 = true;
}
r3._bottom = a0;
if (enabled2) {
r3.setState({
bottom: a0
});
}
};
r24._updateBottomIfNecessary = async () => {
let c31148_0, c31148_1, c31148_2;
let enabled;
L28: {
c31148_0 = void 0;
c31148_1 = void 0;
c31148_2 = void 0;
if (env23668[0]._keyboardEvent != null) {
const _keyboardEvent = env23668[0]._keyboardEvent;
c31148_0 = _keyboardEvent.duration;
c31148_1 = _keyboardEvent.easing;
c31148_2 = await env23668[0]._relativeKeyboardHeight(_keyboardEvent.endCoordinates);
if (env23668[0]._bottom === c31148_2) {
break L28;
}
env23668[0]._setBottom(c31148_2);
const enabled2 = env23668[0].props.enabled;
enabled = enabled2;
if (enabled2 == null) {
enabled = true;
}
if (!(enabled && c31148_0 && c31148_1)) {
break L28;
}
const r80 = c31148_0;
let duration = 10;
const duration2 = r80 > 10 ? c31148_0 : 10;
if (c31148_0 > 10) {
duration = c31148_0;
}
Module342.configureNext({
duration: duration2,
update: {
duration,
type: Module342.Types[c31148_1] || "keyboard"
}
});
break L28;
}
env23668[0]._setBottom(0);
return void 0;
}
};
r24.state = {
bottom: 0
};
r24.viewRef = (0, createRef)();
return r24;
};
_inherits(KeyboardAvoidingView, Component);
c356_1 = async function(c23670_1) {
let r38;
let keyboardVerticalOffset;
const _this = this;
L15: {
L14: {
const _frame = _this._frame;
if (!_frame) {
break L15;
}
if (c23670_1) {
const screenY = c23670_1.screenY;
const keyboardVerticalOffset2 = _this.props.keyboardVerticalOffset;
keyboardVerticalOffset = keyboardVerticalOffset2;
if (keyboardVerticalOffset2 == null) {
keyboardVerticalOffset = 0;
}
const r24 = screenY - keyboardVerticalOffset;
if (_this.props.behavior === "height") {
r38 = Math.max(_this.state.bottom + _frame.y + _frame.height - r24, 0);
break L14;
}
r38 = Math.max(_frame.y + _frame.height - r24, 0);
break L14;
}
break L15;
}
return r38;
}
return 0;
};
export default _createClass(KeyboardAvoidingView, [{
key: "_relativeKeyboardHeight",
value: function _relativeKeyboardHeight(a0) {
const apply = c356_1.apply;
return c356_1.apply(this, arguments);
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(a0, a1) {
let enabled2 = this.props.enabled;
if (enabled2 == null) {
enabled2 = true;
}
if (enabled2) {
enabled2 = this._bottom !== a1.bottom;
}
if (enabled2) {
this.setState({
bottom: this._bottom
});
}
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
if (!KeyboardImpl.isVisible()) {
this._keyboardEvent = null;
this._setBottom(0);
}
this._subscriptions = [KeyboardImpl.addListener("keyboardDidHide", this._onKeyboardHide), KeyboardImpl.addListener("keyboardDidShow", this._onKeyboardChange)];
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this._subscriptions.forEach((_subscription) => {
_subscription.remove();
});
}
}, {
key: "render",
value: function render() {
const props = this.props;
const { behavior, children, contentContainerStyle, enabled: enabled2 = true } = props;
props.keyboardVerticalOffset;
const style = props.style;
props.onLayout;
const rest = _objectWithoutProperties(props, _excluded);
const bottom = enabled2 === true ? this.state.bottom : 0;
if (behavior === "height") {
return <View ref={this.viewRef} style={Module254.compose(style, this._frame != null && this.state.bottom > 0 ? {
height: this._initialFrameHeight - bottom,
flex: 0
} : void 0)} onLayout={this._onLayout} {...rest}>{children}</View>;
}
if (behavior === "position") {
return <View ref={this.viewRef} style={style} onLayout={this._onLayout} {...rest}>
<View style={Module254.compose(contentContainerStyle, {
bottom
})}>{children}</View>
</View>;
}
if (behavior === "padding") {
return <View ref={this.viewRef} style={Module254.compose(style, {
paddingBottom: bottom
})} onLayout={this._onLayout} {...rest}>{children}</View>;
}
return <View ref={this.viewRef} onLayout={this._onLayout} style={style} {...rest}>{children}</View>;
}
}]);