sapo-components-ui-rn 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +393 -372
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +392 -371
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/TextInput/TextInputDefault.tsx +66 -35
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Platform, Dimensions, StyleSheet, useColorScheme, Animated, Easing, View as View$1, I18nManager, TouchableOpacity, NativeModules, Switch as Switch$1, Text as Text$2, Pressable, useWindowDimensions, TextInput as TextInput$1, ActivityIndicator as ActivityIndicator$1, Image as Image$2, ImageBackground } from 'react-native';
|
|
2
2
|
import * as React$3 from 'react';
|
|
3
|
-
import React__default, { useMemo,
|
|
3
|
+
import React__default, { useMemo, memo, forwardRef as forwardRef$1, useRef, useImperativeHandle, useState, useEffect, useCallback } from 'react';
|
|
4
4
|
import require$$1 from 'deepmerge';
|
|
5
5
|
import color from 'color';
|
|
6
6
|
import FontAwesome from 'react-native-vector-icons/FontAwesome';
|
|
@@ -3019,348 +3019,6 @@ var styles$b = StyleSheet.create({
|
|
|
3019
3019
|
},
|
|
3020
3020
|
});
|
|
3021
3021
|
|
|
3022
|
-
var TextInputDefault = function (_a) {
|
|
3023
|
-
var _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.editable, editable = _c === void 0 ? true : _c; _a.label; var _d = _a.error, error = _d === void 0 ? false : _d, customSelectionColor = _a.selectionColor, cursorColor = _a.cursorColor, customOutlineColor = _a.outlineColor, activeOutlineColor = _a.activeOutlineColor; _a.outlineStyle; var textColor = _a.textColor; _a.dense; var style = _a.style, theme = _a.theme, _e = _a.render, render = _e === void 0 ? function (props) { return React$3.createElement(TextInput$1, __assign({}, props)); } : _e, _f = _a.multiline, multiline = _f === void 0 ? false : _f, parentState = _a.parentState, innerRef = _a.innerRef, onFocus = _a.onFocus; _a.forceFocus; var onBlur = _a.onBlur, onChangeText = _a.onChangeText; _a.onLayout; var left = _a.left, right = _a.right, placeholderTextColor = _a.placeholderTextColor, _g = _a.clearButton, clearButton = _g === void 0 ? false : _g, contentStyle = _a.contentStyle, value = _a.value, rest = __rest(_a, ["disabled", "editable", "label", "error", "selectionColor", "cursorColor", "outlineColor", "activeOutlineColor", "outlineStyle", "textColor", "dense", "style", "theme", "render", "multiline", "parentState", "innerRef", "onFocus", "forceFocus", "onBlur", "onChangeText", "onLayout", "left", "right", "placeholderTextColor", "clearButton", "contentStyle", "value"]);
|
|
3024
|
-
var colors = theme.colors;
|
|
3025
|
-
var font = theme.fonts.bodyLarge;
|
|
3026
|
-
var _h = (StyleSheet.flatten(style) || {}), fontSizeStyle = _h.fontSize, fontWeight = _h.fontWeight, lineHeightStyle = _h.lineHeight, height = _h.height, _j = _h.backgroundColor; _j === void 0 ? colors === null || colors === void 0 ? void 0 : colors.backgroundPrimary : _j; var textAlign = _h.textAlign, viewStyle = __rest(_h, ["fontSize", "fontWeight", "lineHeight", "height", "backgroundColor", "textAlign"]);
|
|
3027
|
-
var fontSize = fontSizeStyle || MAXIMIZED_LABEL_FONT_SIZE;
|
|
3028
|
-
var lineHeight = lineHeightStyle || (Platform.OS === "web" ? fontSize * 1.2 : undefined);
|
|
3029
|
-
var _k = getOutlinedInputColors({
|
|
3030
|
-
activeOutlineColor: activeOutlineColor,
|
|
3031
|
-
customOutlineColor: customOutlineColor,
|
|
3032
|
-
customSelectionColor: customSelectionColor,
|
|
3033
|
-
textColor: textColor,
|
|
3034
|
-
disabled: disabled,
|
|
3035
|
-
error: error,
|
|
3036
|
-
theme: theme,
|
|
3037
|
-
}), inputTextColor = _k.inputTextColor, activeColor = _k.activeColor, selectionColor = _k.selectionColor;
|
|
3038
|
-
var _l = React$3.useState(value || ""), inputValue = _l[0], setInputValue = _l[1];
|
|
3039
|
-
React$3.useEffect(function () {
|
|
3040
|
-
setInputValue(value || "");
|
|
3041
|
-
}, [value]);
|
|
3042
|
-
var handleChangeText = function (text) {
|
|
3043
|
-
setInputValue(text);
|
|
3044
|
-
onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(text);
|
|
3045
|
-
};
|
|
3046
|
-
var handleClear = function () {
|
|
3047
|
-
setInputValue("");
|
|
3048
|
-
onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText("");
|
|
3049
|
-
};
|
|
3050
|
-
if (height && typeof height !== "number") {
|
|
3051
|
-
console.warn("Currently we support only numbers in height prop");
|
|
3052
|
-
}
|
|
3053
|
-
var placeholderTextColorBasedOnState = placeholderTextColor || colors.textSecondary;
|
|
3054
|
-
var getBorderColor = function () {
|
|
3055
|
-
if (disabled) {
|
|
3056
|
-
return theme.colors.surfacePrimaryDisabled;
|
|
3057
|
-
}
|
|
3058
|
-
else if (parentState.focused) {
|
|
3059
|
-
return activeColor;
|
|
3060
|
-
}
|
|
3061
|
-
else {
|
|
3062
|
-
return theme.colors.borderPrimaryDefault;
|
|
3063
|
-
}
|
|
3064
|
-
};
|
|
3065
|
-
return (React$3.createElement(View, { style: viewStyle },
|
|
3066
|
-
React$3.createElement(View, { row: true, alignCenter: true, style: [
|
|
3067
|
-
{
|
|
3068
|
-
borderRadius: CONSTANTS.BORDER_RADIUS_6,
|
|
3069
|
-
borderWidth: 1,
|
|
3070
|
-
borderColor: getBorderColor(),
|
|
3071
|
-
overflow: "hidden",
|
|
3072
|
-
backgroundColor: disabled
|
|
3073
|
-
? theme.colors.surfacePrimaryDisabled
|
|
3074
|
-
: theme.colors.surfacePrimaryDefault,
|
|
3075
|
-
},
|
|
3076
|
-
] },
|
|
3077
|
-
React$3.createElement(View, { paddingLeft: CONSTANTS.SPACE_12 }, left),
|
|
3078
|
-
left && React$3.createElement(Spacer, { width: CONSTANTS.SPACE_8 }), render === null || render === void 0 ? void 0 :
|
|
3079
|
-
render(__assign(__assign({}, rest), { ref: innerRef, onChangeText: handleChangeText, value: inputValue, placeholder: rest.placeholder, editable: !disabled && editable, selectionColor: selectionColor, cursorColor: typeof cursorColor === "undefined" ? activeColor : cursorColor, placeholderTextColor: placeholderTextColorBasedOnState, onFocus: onFocus, onBlur: onBlur, underlineColorAndroid: "transparent", multiline: multiline, style: [
|
|
3080
|
-
styles$a.input,
|
|
3081
|
-
__assign(__assign({}, font), { fontSize: fontSize, lineHeight: lineHeight, fontWeight: fontWeight, color: inputTextColor, textAlignVertical: multiline ? "top" : "center", textAlign: textAlign
|
|
3082
|
-
? textAlign
|
|
3083
|
-
: I18nManager.getConstants().isRTL
|
|
3084
|
-
? "right"
|
|
3085
|
-
: "left", height: height ? height : 48 }),
|
|
3086
|
-
contentStyle,
|
|
3087
|
-
] })),
|
|
3088
|
-
!disabled && clearButton && inputValue ? (React$3.createElement(TouchableOpacity, { onPress: handleClear, style: styles$a.clearButton },
|
|
3089
|
-
React$3.createElement(Icon$1, { name: "IconClearText", type: "Svg", size: 24 }))) : (React$3.createElement(Spacer, { width: CONSTANTS.SPACE_12 })),
|
|
3090
|
-
right && React$3.createElement(Spacer, { width: CONSTANTS.SPACE_8 }),
|
|
3091
|
-
right && React$3.createElement(View, { paddingRight: CONSTANTS.SPACE_12 }, right))));
|
|
3092
|
-
};
|
|
3093
|
-
var styles$a = StyleSheet.create({
|
|
3094
|
-
input: {
|
|
3095
|
-
margin: 0,
|
|
3096
|
-
flex: 1,
|
|
3097
|
-
height: 48,
|
|
3098
|
-
},
|
|
3099
|
-
clearButton: {
|
|
3100
|
-
padding: CONSTANTS.SPACE_8,
|
|
3101
|
-
},
|
|
3102
|
-
});
|
|
3103
|
-
|
|
3104
|
-
var roundLayoutSize = function (size) {
|
|
3105
|
-
return Math.round(size * 1000) / 1000;
|
|
3106
|
-
};
|
|
3107
|
-
|
|
3108
|
-
var BLUR_ANIMATION_DURATION = 180;
|
|
3109
|
-
var FOCUS_ANIMATION_DURATION = 150;
|
|
3110
|
-
var DefaultRenderer = function (props) { return React__default.createElement(TextInput$1, __assign({}, props)); };
|
|
3111
|
-
/**
|
|
3112
|
-
* A component to allow users to input text.
|
|
3113
|
-
*
|
|
3114
|
-
* ## Usage
|
|
3115
|
-
* ```js
|
|
3116
|
-
* import * as React from 'react';
|
|
3117
|
-
* import { TextInput } from 'react-native-paper';
|
|
3118
|
-
*
|
|
3119
|
-
* const MyComponent = () => {
|
|
3120
|
-
* const [text, setText] = React.useState("");
|
|
3121
|
-
*
|
|
3122
|
-
* return (
|
|
3123
|
-
* <TextInput
|
|
3124
|
-
* label="Email"
|
|
3125
|
-
* value={text}
|
|
3126
|
-
* onChangeText={text => setText(text)}
|
|
3127
|
-
* />
|
|
3128
|
-
* );
|
|
3129
|
-
* };
|
|
3130
|
-
*
|
|
3131
|
-
* export default MyComponent;
|
|
3132
|
-
* ```
|
|
3133
|
-
*
|
|
3134
|
-
* @extends TextInput props https://reactnative.dev/docs/textinput#props
|
|
3135
|
-
*/
|
|
3136
|
-
var TextInput = forwardRef(function (_a, ref) {
|
|
3137
|
-
var _b = _a.mode, mode = _b === void 0 ? "default" : _b, _c = _a.dense, dense = _c === void 0 ? false : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.error, errorProp = _e === void 0 ? false : _e, _f = _a.multiline, multiline = _f === void 0 ? false : _f, _g = _a.editable, editable = _g === void 0 ? true : _g, contentStyle = _a.contentStyle, _h = _a.render, render = _h === void 0 ? DefaultRenderer : _h; _a.theme; var placeholderTextColor = _a.placeholderTextColor, clearButton = _a.clearButton, rest = __rest(_a, ["mode", "dense", "disabled", "error", "multiline", "editable", "contentStyle", "render", "theme", "placeholderTextColor", "clearButton"]);
|
|
3138
|
-
var theme = useInternalTheme();
|
|
3139
|
-
var isControlled = rest.value !== undefined;
|
|
3140
|
-
var validInputValue = isControlled ? rest.value : rest.defaultValue;
|
|
3141
|
-
var labeled = React__default.useRef(new Animated.Value(validInputValue ? 0 : 1)).current;
|
|
3142
|
-
var error = React__default.useRef(new Animated.Value(errorProp ? 1 : 0)).current;
|
|
3143
|
-
var _j = React__default.useState(false), focused = _j[0], setFocused = _j[1];
|
|
3144
|
-
var _k = React__default.useState(false), displayPlaceholder = _k[0], setDisplayPlaceholder = _k[1];
|
|
3145
|
-
var _l = React__default.useState(validInputValue), uncontrolledValue = _l[0], setUncontrolledValue = _l[1];
|
|
3146
|
-
// Use value from props instead of local state when input is controlled
|
|
3147
|
-
var value = isControlled ? rest.value : uncontrolledValue;
|
|
3148
|
-
var _m = React__default.useState({
|
|
3149
|
-
width: 33,
|
|
3150
|
-
}), labelTextLayout = _m[0], setLabelTextLayout = _m[1];
|
|
3151
|
-
var _o = React__default.useState({
|
|
3152
|
-
width: 65,
|
|
3153
|
-
}), inputContainerLayout = _o[0], setInputContainerLayout = _o[1];
|
|
3154
|
-
var _p = React__default.useState({
|
|
3155
|
-
measured: false,
|
|
3156
|
-
width: 0,
|
|
3157
|
-
height: 0,
|
|
3158
|
-
}), labelLayout = _p[0], setLabelLayout = _p[1];
|
|
3159
|
-
var _q = React__default.useState({
|
|
3160
|
-
width: null,
|
|
3161
|
-
height: null,
|
|
3162
|
-
}), leftLayout = _q[0], setLeftLayout = _q[1];
|
|
3163
|
-
var _r = React__default.useState({
|
|
3164
|
-
width: null,
|
|
3165
|
-
height: null,
|
|
3166
|
-
}), rightLayout = _r[0], setRightLayout = _r[1];
|
|
3167
|
-
var timer = useRef(undefined);
|
|
3168
|
-
var root = useRef(null);
|
|
3169
|
-
var scale = theme.animation.scale;
|
|
3170
|
-
React__default.useImperativeHandle(ref, function () { return ({
|
|
3171
|
-
focus: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
3172
|
-
clear: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.clear(); },
|
|
3173
|
-
setNativeProps: function (args) { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.setNativeProps(args); },
|
|
3174
|
-
isFocused: function () { var _a; return ((_a = root.current) === null || _a === void 0 ? void 0 : _a.isFocused()) || false; },
|
|
3175
|
-
blur: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.blur(); },
|
|
3176
|
-
forceFocus: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
3177
|
-
}); });
|
|
3178
|
-
React__default.useEffect(function () {
|
|
3179
|
-
// When the input has an error, we wiggle the label and apply error styles
|
|
3180
|
-
if (errorProp) {
|
|
3181
|
-
// show error
|
|
3182
|
-
Animated.timing(error, {
|
|
3183
|
-
toValue: 1,
|
|
3184
|
-
duration: FOCUS_ANIMATION_DURATION * scale,
|
|
3185
|
-
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
3186
|
-
useNativeDriver: true,
|
|
3187
|
-
}).start();
|
|
3188
|
-
}
|
|
3189
|
-
else {
|
|
3190
|
-
// hide error
|
|
3191
|
-
{
|
|
3192
|
-
Animated.timing(error, {
|
|
3193
|
-
toValue: 0,
|
|
3194
|
-
duration: BLUR_ANIMATION_DURATION * scale,
|
|
3195
|
-
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
3196
|
-
useNativeDriver: true,
|
|
3197
|
-
}).start();
|
|
3198
|
-
}
|
|
3199
|
-
}
|
|
3200
|
-
}, [errorProp, scale, error]);
|
|
3201
|
-
React__default.useEffect(function () {
|
|
3202
|
-
// Show placeholder text only if the input is focused, or there's no label
|
|
3203
|
-
// We don't show placeholder if there's a label because the label acts as placeholder
|
|
3204
|
-
// When focused, the label moves up, so we can show a placeholder
|
|
3205
|
-
if (focused || !rest.label) {
|
|
3206
|
-
// If the user wants to use the contextMenu, when changing the placeholder, the contextMenu is closed
|
|
3207
|
-
// This is a workaround to mitigate this behavior in scenarios where the placeholder is not specified.
|
|
3208
|
-
if (rest.placeholder) {
|
|
3209
|
-
// Display placeholder in a delay to offset the label animation
|
|
3210
|
-
// If we show it immediately, they'll overlap and look ugly
|
|
3211
|
-
timer.current = setTimeout(function () { return setDisplayPlaceholder(true); }, 50);
|
|
3212
|
-
}
|
|
3213
|
-
}
|
|
3214
|
-
else {
|
|
3215
|
-
// hidePlaceholder
|
|
3216
|
-
setDisplayPlaceholder(false);
|
|
3217
|
-
}
|
|
3218
|
-
return function () {
|
|
3219
|
-
if (timer.current) {
|
|
3220
|
-
clearTimeout(timer.current);
|
|
3221
|
-
}
|
|
3222
|
-
};
|
|
3223
|
-
}, [focused, rest.label, rest.placeholder]);
|
|
3224
|
-
React__default.useEffect(function () {
|
|
3225
|
-
labeled.stopAnimation();
|
|
3226
|
-
// The label should be minimized if the text input is focused, or has text
|
|
3227
|
-
// In minimized mode, the label moves up and becomes small
|
|
3228
|
-
// workaround for animated regression for react native > 0.61
|
|
3229
|
-
// https://github.com/callstack/react-native-paper/pull/1440
|
|
3230
|
-
if (value || focused) {
|
|
3231
|
-
// minimize label
|
|
3232
|
-
Animated.timing(labeled, {
|
|
3233
|
-
toValue: 0,
|
|
3234
|
-
duration: BLUR_ANIMATION_DURATION * scale,
|
|
3235
|
-
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
3236
|
-
useNativeDriver: true,
|
|
3237
|
-
}).start();
|
|
3238
|
-
}
|
|
3239
|
-
else {
|
|
3240
|
-
// restore label
|
|
3241
|
-
Animated.timing(labeled, {
|
|
3242
|
-
toValue: 1,
|
|
3243
|
-
duration: FOCUS_ANIMATION_DURATION * scale,
|
|
3244
|
-
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
3245
|
-
useNativeDriver: true,
|
|
3246
|
-
}).start();
|
|
3247
|
-
}
|
|
3248
|
-
}, [focused, value, labeled, scale]);
|
|
3249
|
-
var onLeftAffixLayoutChange = React__default.useCallback(function (event) {
|
|
3250
|
-
var height = roundLayoutSize(event.nativeEvent.layout.height);
|
|
3251
|
-
var width = roundLayoutSize(event.nativeEvent.layout.width);
|
|
3252
|
-
if (width !== leftLayout.width || height !== leftLayout.height) {
|
|
3253
|
-
setLeftLayout({
|
|
3254
|
-
width: width,
|
|
3255
|
-
height: height,
|
|
3256
|
-
});
|
|
3257
|
-
}
|
|
3258
|
-
}, [leftLayout.height, leftLayout.width]);
|
|
3259
|
-
var onRightAffixLayoutChange = React__default.useCallback(function (event) {
|
|
3260
|
-
var width = roundLayoutSize(event.nativeEvent.layout.width);
|
|
3261
|
-
var height = roundLayoutSize(event.nativeEvent.layout.height);
|
|
3262
|
-
if (width !== rightLayout.width || height !== rightLayout.height) {
|
|
3263
|
-
setRightLayout({
|
|
3264
|
-
width: width,
|
|
3265
|
-
height: height,
|
|
3266
|
-
});
|
|
3267
|
-
}
|
|
3268
|
-
}, [rightLayout.height, rightLayout.width]);
|
|
3269
|
-
var handleFocus = function (args) {
|
|
3270
|
-
var _a;
|
|
3271
|
-
if (disabled || !editable) {
|
|
3272
|
-
return;
|
|
3273
|
-
}
|
|
3274
|
-
setFocused(true);
|
|
3275
|
-
(_a = rest.onFocus) === null || _a === void 0 ? void 0 : _a.call(rest, args);
|
|
3276
|
-
};
|
|
3277
|
-
var handleBlur = function (args) {
|
|
3278
|
-
var _a;
|
|
3279
|
-
if (!editable) {
|
|
3280
|
-
return;
|
|
3281
|
-
}
|
|
3282
|
-
setFocused(false);
|
|
3283
|
-
(_a = rest.onBlur) === null || _a === void 0 ? void 0 : _a.call(rest, args);
|
|
3284
|
-
};
|
|
3285
|
-
var handleChangeText = function (value) {
|
|
3286
|
-
var _a;
|
|
3287
|
-
if (!editable || disabled) {
|
|
3288
|
-
return;
|
|
3289
|
-
}
|
|
3290
|
-
if (!isControlled) {
|
|
3291
|
-
// Keep track of value in local state when input is not controlled
|
|
3292
|
-
setUncontrolledValue(value);
|
|
3293
|
-
}
|
|
3294
|
-
(_a = rest.onChangeText) === null || _a === void 0 ? void 0 : _a.call(rest, value);
|
|
3295
|
-
};
|
|
3296
|
-
var handleLayoutAnimatedText = React__default.useCallback(function (e) {
|
|
3297
|
-
var width = roundLayoutSize(e.nativeEvent.layout.width);
|
|
3298
|
-
var height = roundLayoutSize(e.nativeEvent.layout.height);
|
|
3299
|
-
if (width !== labelLayout.width || height !== labelLayout.height) {
|
|
3300
|
-
setLabelLayout({
|
|
3301
|
-
width: width,
|
|
3302
|
-
height: height,
|
|
3303
|
-
measured: true,
|
|
3304
|
-
});
|
|
3305
|
-
}
|
|
3306
|
-
}, [labelLayout.height, labelLayout.width]);
|
|
3307
|
-
var handleLabelTextLayout = React__default.useCallback(function (_a) {
|
|
3308
|
-
var nativeEvent = _a.nativeEvent;
|
|
3309
|
-
setLabelTextLayout({
|
|
3310
|
-
width: nativeEvent.lines.reduce(function (acc, line) { return acc + Math.ceil(line.width); }, 0),
|
|
3311
|
-
});
|
|
3312
|
-
}, []);
|
|
3313
|
-
var handleInputContainerLayout = React__default.useCallback(function (_a) {
|
|
3314
|
-
var layout = _a.nativeEvent.layout;
|
|
3315
|
-
setInputContainerLayout({
|
|
3316
|
-
width: layout.width,
|
|
3317
|
-
});
|
|
3318
|
-
}, []);
|
|
3319
|
-
var forceFocus = React__default.useCallback(function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); }, []);
|
|
3320
|
-
var _s = rest.maxFontSizeMultiplier, maxFontSizeMultiplier = _s === void 0 ? 1.5 : _s;
|
|
3321
|
-
var scaledLabel = !!(value || focused);
|
|
3322
|
-
if (mode === "default") {
|
|
3323
|
-
return (React__default.createElement(TextInputDefault, __assign({ dense: dense, disabled: disabled, error: errorProp, multiline: multiline, editable: editable, render: render }, rest, { theme: theme, value: value, placeholderTextColor: placeholderTextColor, clearButton: clearButton, parentState: {
|
|
3324
|
-
labeled: labeled,
|
|
3325
|
-
error: error,
|
|
3326
|
-
focused: focused,
|
|
3327
|
-
displayPlaceholder: displayPlaceholder,
|
|
3328
|
-
value: value,
|
|
3329
|
-
labelTextLayout: labelTextLayout,
|
|
3330
|
-
labelLayout: labelLayout,
|
|
3331
|
-
leftLayout: leftLayout,
|
|
3332
|
-
rightLayout: rightLayout,
|
|
3333
|
-
inputContainerLayout: inputContainerLayout,
|
|
3334
|
-
}, innerRef: function (ref) {
|
|
3335
|
-
root.current = ref;
|
|
3336
|
-
}, onFocus: handleFocus, forceFocus: forceFocus, onBlur: handleBlur, allowFontScaling: false, onChangeText: handleChangeText, onLayoutAnimatedText: handleLayoutAnimatedText, onInputLayout: handleInputContainerLayout, onLabelTextLayout: handleLabelTextLayout, onLeftAffixLayoutChange: onLeftAffixLayoutChange, onRightAffixLayoutChange: onRightAffixLayoutChange, maxFontSizeMultiplier: maxFontSizeMultiplier, contentStyle: contentStyle, scaledLabel: scaledLabel })));
|
|
3337
|
-
}
|
|
3338
|
-
return (React__default.createElement(TextInputFlat, __assign({ dense: dense, disabled: disabled, error: errorProp, multiline: false, editable: editable, clearButton: clearButton, render: render }, rest, { theme: theme, value: value, parentState: {
|
|
3339
|
-
labeled: labeled,
|
|
3340
|
-
error: error,
|
|
3341
|
-
focused: focused,
|
|
3342
|
-
displayPlaceholder: displayPlaceholder,
|
|
3343
|
-
value: value,
|
|
3344
|
-
labelTextLayout: labelTextLayout,
|
|
3345
|
-
labelLayout: labelLayout,
|
|
3346
|
-
leftLayout: leftLayout,
|
|
3347
|
-
rightLayout: rightLayout,
|
|
3348
|
-
inputContainerLayout: inputContainerLayout,
|
|
3349
|
-
}, innerRef: function (ref) {
|
|
3350
|
-
root.current = ref;
|
|
3351
|
-
}, onFocus: handleFocus, forceFocus: forceFocus, onBlur: handleBlur, onInputLayout: handleInputContainerLayout, allowFontScaling: false, onChangeText: handleChangeText, onLayoutAnimatedText: handleLayoutAnimatedText, onLabelTextLayout: handleLabelTextLayout, onLeftAffixLayoutChange: onLeftAffixLayoutChange, onRightAffixLayoutChange: onRightAffixLayoutChange, maxFontSizeMultiplier: maxFontSizeMultiplier, contentStyle: contentStyle, scaledLabel: scaledLabel })));
|
|
3352
|
-
});
|
|
3353
|
-
// @component ./Adornment/TextInputIcon.tsx
|
|
3354
|
-
// @component ./Adornment/TextInputAffix.tsx
|
|
3355
|
-
// @ts-ignore Types of property 'theme' are incompatible.
|
|
3356
|
-
TextInput.Affix = TextInputAffix;
|
|
3357
|
-
|
|
3358
|
-
var ScaleButton = function (_a) {
|
|
3359
|
-
var children = _a.children; _a.style; var _b = _a.onPress, onPress = _b === void 0 ? function () { } : _b, rest = __rest(_a, ["children", "style", "onPress"]);
|
|
3360
|
-
return (React__default.createElement(TouchableOpacity, __assign({}, rest, { onPress: onPress }), children));
|
|
3361
|
-
};
|
|
3362
|
-
var ScaleButton$1 = React__default.memo(ScaleButton);
|
|
3363
|
-
|
|
3364
3022
|
/**
|
|
3365
3023
|
* Removes all key-value entries from the list cache.
|
|
3366
3024
|
*
|
|
@@ -5827,43 +5485,406 @@ var memoWithRef = function (component) {
|
|
|
5827
5485
|
var Text = function (props) {
|
|
5828
5486
|
var children = props.children, onPress = props.onPress; props.theme; var rest = __rest(props, ["children", "onPress", "theme"]);
|
|
5829
5487
|
var theme = useInternalTheme();
|
|
5830
|
-
delete rest.style;
|
|
5831
|
-
var _getStyle = function () {
|
|
5832
|
-
var style = {
|
|
5833
|
-
fontWeight: "normal",
|
|
5834
|
-
color: colors.ink.INK100,
|
|
5835
|
-
fontFamily: "Inter-Regular",
|
|
5836
|
-
};
|
|
5837
|
-
var _a = props.size, size = _a === void 0 ? 14 : _a, center = props.center, color = props.color, bold = props.bold, medium = props.medium;
|
|
5838
|
-
style.color = theme.colors.textDefault || "black";
|
|
5839
|
-
if (size) {
|
|
5840
|
-
style.fontSize = size;
|
|
5841
|
-
}
|
|
5842
|
-
if (color) {
|
|
5843
|
-
style.color = color;
|
|
5488
|
+
delete rest.style;
|
|
5489
|
+
var _getStyle = function () {
|
|
5490
|
+
var style = {
|
|
5491
|
+
fontWeight: "normal",
|
|
5492
|
+
color: colors.ink.INK100,
|
|
5493
|
+
fontFamily: "Inter-Regular",
|
|
5494
|
+
};
|
|
5495
|
+
var _a = props.size, size = _a === void 0 ? 14 : _a, center = props.center, color = props.color, bold = props.bold, medium = props.medium;
|
|
5496
|
+
style.color = theme.colors.textDefault || "black";
|
|
5497
|
+
if (size) {
|
|
5498
|
+
style.fontSize = size;
|
|
5499
|
+
}
|
|
5500
|
+
if (color) {
|
|
5501
|
+
style.color = color;
|
|
5502
|
+
}
|
|
5503
|
+
if (center) {
|
|
5504
|
+
style.textAlign = "center";
|
|
5505
|
+
}
|
|
5506
|
+
if (bold) {
|
|
5507
|
+
style.fontFamily = "Inter-Bold";
|
|
5508
|
+
if (Platform.OS === "ios") {
|
|
5509
|
+
style.fontWeight = "bold";
|
|
5510
|
+
}
|
|
5511
|
+
}
|
|
5512
|
+
if (medium) {
|
|
5513
|
+
style.fontFamily = "Inter-SemiBold";
|
|
5514
|
+
if (Platform.OS === "ios") {
|
|
5515
|
+
style.fontWeight = "600";
|
|
5516
|
+
}
|
|
5517
|
+
}
|
|
5518
|
+
return StyleSheet.create({ style: style }).style;
|
|
5519
|
+
};
|
|
5520
|
+
var defaultStyle = _getStyle();
|
|
5521
|
+
var Component = Text$2;
|
|
5522
|
+
return (React__default.createElement(Component, __assign({ onPress: onPress, style: [defaultStyle, props.style], allowFontScaling: false }, rest), children));
|
|
5523
|
+
};
|
|
5524
|
+
var Text$1 = memoDeepEqual(Text);
|
|
5525
|
+
|
|
5526
|
+
var TextInputDefault = function (_a) {
|
|
5527
|
+
var _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.editable, editable = _c === void 0 ? true : _c, label = _a.label, _d = _a.error, error = _d === void 0 ? false : _d, customSelectionColor = _a.selectionColor, cursorColor = _a.cursorColor, customOutlineColor = _a.outlineColor, activeOutlineColor = _a.activeOutlineColor; _a.outlineStyle; var textColor = _a.textColor; _a.dense; var style = _a.style, theme = _a.theme, _e = _a.render, render = _e === void 0 ? function (props) { return React$3.createElement(TextInput$1, __assign({}, props)); } : _e, _f = _a.multiline, multiline = _f === void 0 ? false : _f, parentState = _a.parentState, innerRef = _a.innerRef, onFocus = _a.onFocus; _a.forceFocus; var onBlur = _a.onBlur, onChangeText = _a.onChangeText; _a.onLayout; var left = _a.left, right = _a.right, placeholderTextColor = _a.placeholderTextColor, _g = _a.clearButton, clearButton = _g === void 0 ? false : _g, contentStyle = _a.contentStyle, value = _a.value, rest = __rest(_a, ["disabled", "editable", "label", "error", "selectionColor", "cursorColor", "outlineColor", "activeOutlineColor", "outlineStyle", "textColor", "dense", "style", "theme", "render", "multiline", "parentState", "innerRef", "onFocus", "forceFocus", "onBlur", "onChangeText", "onLayout", "left", "right", "placeholderTextColor", "clearButton", "contentStyle", "value"]);
|
|
5528
|
+
var colors = theme.colors;
|
|
5529
|
+
var font = theme.fonts.bodyLarge;
|
|
5530
|
+
var _h = (StyleSheet.flatten(style) || {}), fontSizeStyle = _h.fontSize, fontWeight = _h.fontWeight, lineHeightStyle = _h.lineHeight, height = _h.height, _j = _h.backgroundColor; _j === void 0 ? colors === null || colors === void 0 ? void 0 : colors.backgroundPrimary : _j; var textAlign = _h.textAlign, viewStyle = __rest(_h, ["fontSize", "fontWeight", "lineHeight", "height", "backgroundColor", "textAlign"]);
|
|
5531
|
+
var fontSize = fontSizeStyle || MAXIMIZED_LABEL_FONT_SIZE;
|
|
5532
|
+
var lineHeight = lineHeightStyle || (Platform.OS === "web" ? fontSize * 1.2 : undefined);
|
|
5533
|
+
var _k = getOutlinedInputColors({
|
|
5534
|
+
activeOutlineColor: activeOutlineColor,
|
|
5535
|
+
customOutlineColor: customOutlineColor,
|
|
5536
|
+
customSelectionColor: customSelectionColor,
|
|
5537
|
+
textColor: textColor,
|
|
5538
|
+
disabled: disabled,
|
|
5539
|
+
error: error,
|
|
5540
|
+
theme: theme,
|
|
5541
|
+
}), inputTextColor = _k.inputTextColor, activeColor = _k.activeColor, selectionColor = _k.selectionColor;
|
|
5542
|
+
var _l = React$3.useState(value || ""), inputValue = _l[0], setInputValue = _l[1];
|
|
5543
|
+
React$3.useEffect(function () {
|
|
5544
|
+
setInputValue(value || "");
|
|
5545
|
+
}, [value]);
|
|
5546
|
+
var handleChangeText = function (text) {
|
|
5547
|
+
setInputValue(text);
|
|
5548
|
+
onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(text);
|
|
5549
|
+
};
|
|
5550
|
+
var handleClear = function () {
|
|
5551
|
+
setInputValue("");
|
|
5552
|
+
onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText("");
|
|
5553
|
+
};
|
|
5554
|
+
if (height && typeof height !== "number") {
|
|
5555
|
+
console.warn("Currently we support only numbers in height prop");
|
|
5556
|
+
}
|
|
5557
|
+
var placeholderTextColorBasedOnState = placeholderTextColor || colors.textSecondary;
|
|
5558
|
+
var getBorderColor = function () {
|
|
5559
|
+
if (disabled) {
|
|
5560
|
+
return theme.colors.surfacePrimaryDisabled;
|
|
5561
|
+
}
|
|
5562
|
+
else if (parentState.focused) {
|
|
5563
|
+
return activeColor;
|
|
5564
|
+
}
|
|
5565
|
+
else {
|
|
5566
|
+
return theme.colors.borderPrimaryDefault;
|
|
5567
|
+
}
|
|
5568
|
+
};
|
|
5569
|
+
var getLabelColor = function () {
|
|
5570
|
+
if (disabled) {
|
|
5571
|
+
return theme.colors.textSecondary;
|
|
5572
|
+
}
|
|
5573
|
+
else if (parentState.focused) {
|
|
5574
|
+
return activeColor;
|
|
5575
|
+
}
|
|
5576
|
+
else {
|
|
5577
|
+
return theme.colors.textSecondary;
|
|
5578
|
+
}
|
|
5579
|
+
};
|
|
5580
|
+
var renderLabel = function () {
|
|
5581
|
+
var _a;
|
|
5582
|
+
if (parentState.focused || ((_a = parentState.value) === null || _a === void 0 ? void 0 : _a.toString()) !== "") {
|
|
5583
|
+
return (React$3.createElement(View, { paddingTop: CONSTANTS.SPACE_4 },
|
|
5584
|
+
React$3.createElement(Text$1, { color: getLabelColor(), size: MINIMIZED_LABEL_FONT_SIZE }, label)));
|
|
5585
|
+
}
|
|
5586
|
+
return React$3.createElement(View, null);
|
|
5587
|
+
};
|
|
5588
|
+
return (React$3.createElement(View, { style: viewStyle },
|
|
5589
|
+
React$3.createElement(View, { row: true, alignCenter: true, style: [
|
|
5590
|
+
{
|
|
5591
|
+
borderRadius: CONSTANTS.BORDER_RADIUS_6,
|
|
5592
|
+
borderWidth: 1,
|
|
5593
|
+
borderColor: getBorderColor(),
|
|
5594
|
+
overflow: "hidden",
|
|
5595
|
+
backgroundColor: disabled
|
|
5596
|
+
? theme.colors.surfacePrimaryDisabled
|
|
5597
|
+
: theme.colors.surfacePrimaryDefault,
|
|
5598
|
+
},
|
|
5599
|
+
] },
|
|
5600
|
+
React$3.createElement(View, { paddingLeft: CONSTANTS.SPACE_12 }, left),
|
|
5601
|
+
left && React$3.createElement(Spacer, { width: CONSTANTS.SPACE_8 }),
|
|
5602
|
+
React$3.createElement(View, { full: true },
|
|
5603
|
+
renderLabel(), render === null || render === void 0 ? void 0 :
|
|
5604
|
+
render(__assign(__assign({}, rest), { ref: innerRef, onChangeText: handleChangeText, value: inputValue, placeholder: rest.placeholder, editable: !disabled && editable, selectionColor: selectionColor, cursorColor: typeof cursorColor === "undefined" ? activeColor : cursorColor, placeholderTextColor: placeholderTextColorBasedOnState, onFocus: onFocus, onBlur: onBlur, underlineColorAndroid: "transparent", multiline: multiline, style: [
|
|
5605
|
+
styles$a.input,
|
|
5606
|
+
__assign(__assign({}, font), { fontSize: fontSize, lineHeight: lineHeight, fontWeight: fontWeight, color: inputTextColor, textAlignVertical: multiline ? "top" : "center", textAlign: textAlign
|
|
5607
|
+
? textAlign
|
|
5608
|
+
: I18nManager.getConstants().isRTL
|
|
5609
|
+
? "right"
|
|
5610
|
+
: "left", height: height ? height : 48 }),
|
|
5611
|
+
contentStyle,
|
|
5612
|
+
] }))),
|
|
5613
|
+
!disabled && clearButton && inputValue ? (React$3.createElement(TouchableOpacity, { onPress: handleClear, style: styles$a.clearButton },
|
|
5614
|
+
React$3.createElement(Icon$1, { name: "IconClearText", type: "Svg", size: 24 }))) : (React$3.createElement(Spacer, { width: CONSTANTS.SPACE_12 })),
|
|
5615
|
+
right && React$3.createElement(Spacer, { width: CONSTANTS.SPACE_8 }),
|
|
5616
|
+
right && React$3.createElement(View, { paddingRight: CONSTANTS.SPACE_12 }, right))));
|
|
5617
|
+
};
|
|
5618
|
+
var styles$a = StyleSheet.create({
|
|
5619
|
+
input: {
|
|
5620
|
+
margin: 0,
|
|
5621
|
+
flex: 1,
|
|
5622
|
+
height: 48,
|
|
5623
|
+
},
|
|
5624
|
+
clearButton: {
|
|
5625
|
+
padding: CONSTANTS.SPACE_8,
|
|
5626
|
+
},
|
|
5627
|
+
});
|
|
5628
|
+
|
|
5629
|
+
var roundLayoutSize = function (size) {
|
|
5630
|
+
return Math.round(size * 1000) / 1000;
|
|
5631
|
+
};
|
|
5632
|
+
|
|
5633
|
+
var BLUR_ANIMATION_DURATION = 180;
|
|
5634
|
+
var FOCUS_ANIMATION_DURATION = 150;
|
|
5635
|
+
var DefaultRenderer = function (props) { return React__default.createElement(TextInput$1, __assign({}, props)); };
|
|
5636
|
+
/**
|
|
5637
|
+
* A component to allow users to input text.
|
|
5638
|
+
*
|
|
5639
|
+
* ## Usage
|
|
5640
|
+
* ```js
|
|
5641
|
+
* import * as React from 'react';
|
|
5642
|
+
* import { TextInput } from 'react-native-paper';
|
|
5643
|
+
*
|
|
5644
|
+
* const MyComponent = () => {
|
|
5645
|
+
* const [text, setText] = React.useState("");
|
|
5646
|
+
*
|
|
5647
|
+
* return (
|
|
5648
|
+
* <TextInput
|
|
5649
|
+
* label="Email"
|
|
5650
|
+
* value={text}
|
|
5651
|
+
* onChangeText={text => setText(text)}
|
|
5652
|
+
* />
|
|
5653
|
+
* );
|
|
5654
|
+
* };
|
|
5655
|
+
*
|
|
5656
|
+
* export default MyComponent;
|
|
5657
|
+
* ```
|
|
5658
|
+
*
|
|
5659
|
+
* @extends TextInput props https://reactnative.dev/docs/textinput#props
|
|
5660
|
+
*/
|
|
5661
|
+
var TextInput = forwardRef(function (_a, ref) {
|
|
5662
|
+
var _b = _a.mode, mode = _b === void 0 ? "default" : _b, _c = _a.dense, dense = _c === void 0 ? false : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.error, errorProp = _e === void 0 ? false : _e, _f = _a.multiline, multiline = _f === void 0 ? false : _f, _g = _a.editable, editable = _g === void 0 ? true : _g, contentStyle = _a.contentStyle, _h = _a.render, render = _h === void 0 ? DefaultRenderer : _h; _a.theme; var placeholderTextColor = _a.placeholderTextColor, clearButton = _a.clearButton, rest = __rest(_a, ["mode", "dense", "disabled", "error", "multiline", "editable", "contentStyle", "render", "theme", "placeholderTextColor", "clearButton"]);
|
|
5663
|
+
var theme = useInternalTheme();
|
|
5664
|
+
var isControlled = rest.value !== undefined;
|
|
5665
|
+
var validInputValue = isControlled ? rest.value : rest.defaultValue;
|
|
5666
|
+
var labeled = React__default.useRef(new Animated.Value(validInputValue ? 0 : 1)).current;
|
|
5667
|
+
var error = React__default.useRef(new Animated.Value(errorProp ? 1 : 0)).current;
|
|
5668
|
+
var _j = React__default.useState(false), focused = _j[0], setFocused = _j[1];
|
|
5669
|
+
var _k = React__default.useState(false), displayPlaceholder = _k[0], setDisplayPlaceholder = _k[1];
|
|
5670
|
+
var _l = React__default.useState(validInputValue), uncontrolledValue = _l[0], setUncontrolledValue = _l[1];
|
|
5671
|
+
// Use value from props instead of local state when input is controlled
|
|
5672
|
+
var value = isControlled ? rest.value : uncontrolledValue;
|
|
5673
|
+
var _m = React__default.useState({
|
|
5674
|
+
width: 33,
|
|
5675
|
+
}), labelTextLayout = _m[0], setLabelTextLayout = _m[1];
|
|
5676
|
+
var _o = React__default.useState({
|
|
5677
|
+
width: 65,
|
|
5678
|
+
}), inputContainerLayout = _o[0], setInputContainerLayout = _o[1];
|
|
5679
|
+
var _p = React__default.useState({
|
|
5680
|
+
measured: false,
|
|
5681
|
+
width: 0,
|
|
5682
|
+
height: 0,
|
|
5683
|
+
}), labelLayout = _p[0], setLabelLayout = _p[1];
|
|
5684
|
+
var _q = React__default.useState({
|
|
5685
|
+
width: null,
|
|
5686
|
+
height: null,
|
|
5687
|
+
}), leftLayout = _q[0], setLeftLayout = _q[1];
|
|
5688
|
+
var _r = React__default.useState({
|
|
5689
|
+
width: null,
|
|
5690
|
+
height: null,
|
|
5691
|
+
}), rightLayout = _r[0], setRightLayout = _r[1];
|
|
5692
|
+
var timer = useRef(undefined);
|
|
5693
|
+
var root = useRef(null);
|
|
5694
|
+
var scale = theme.animation.scale;
|
|
5695
|
+
React__default.useImperativeHandle(ref, function () { return ({
|
|
5696
|
+
focus: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
5697
|
+
clear: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.clear(); },
|
|
5698
|
+
setNativeProps: function (args) { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.setNativeProps(args); },
|
|
5699
|
+
isFocused: function () { var _a; return ((_a = root.current) === null || _a === void 0 ? void 0 : _a.isFocused()) || false; },
|
|
5700
|
+
blur: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.blur(); },
|
|
5701
|
+
forceFocus: function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
5702
|
+
}); });
|
|
5703
|
+
React__default.useEffect(function () {
|
|
5704
|
+
// When the input has an error, we wiggle the label and apply error styles
|
|
5705
|
+
if (errorProp) {
|
|
5706
|
+
// show error
|
|
5707
|
+
Animated.timing(error, {
|
|
5708
|
+
toValue: 1,
|
|
5709
|
+
duration: FOCUS_ANIMATION_DURATION * scale,
|
|
5710
|
+
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
5711
|
+
useNativeDriver: true,
|
|
5712
|
+
}).start();
|
|
5844
5713
|
}
|
|
5845
|
-
|
|
5846
|
-
|
|
5714
|
+
else {
|
|
5715
|
+
// hide error
|
|
5716
|
+
{
|
|
5717
|
+
Animated.timing(error, {
|
|
5718
|
+
toValue: 0,
|
|
5719
|
+
duration: BLUR_ANIMATION_DURATION * scale,
|
|
5720
|
+
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
5721
|
+
useNativeDriver: true,
|
|
5722
|
+
}).start();
|
|
5723
|
+
}
|
|
5847
5724
|
}
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5725
|
+
}, [errorProp, scale, error]);
|
|
5726
|
+
React__default.useEffect(function () {
|
|
5727
|
+
// Show placeholder text only if the input is focused, or there's no label
|
|
5728
|
+
// We don't show placeholder if there's a label because the label acts as placeholder
|
|
5729
|
+
// When focused, the label moves up, so we can show a placeholder
|
|
5730
|
+
if (focused || !rest.label) {
|
|
5731
|
+
// If the user wants to use the contextMenu, when changing the placeholder, the contextMenu is closed
|
|
5732
|
+
// This is a workaround to mitigate this behavior in scenarios where the placeholder is not specified.
|
|
5733
|
+
if (rest.placeholder) {
|
|
5734
|
+
// Display placeholder in a delay to offset the label animation
|
|
5735
|
+
// If we show it immediately, they'll overlap and look ugly
|
|
5736
|
+
timer.current = setTimeout(function () { return setDisplayPlaceholder(true); }, 50);
|
|
5852
5737
|
}
|
|
5853
5738
|
}
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5739
|
+
else {
|
|
5740
|
+
// hidePlaceholder
|
|
5741
|
+
setDisplayPlaceholder(false);
|
|
5742
|
+
}
|
|
5743
|
+
return function () {
|
|
5744
|
+
if (timer.current) {
|
|
5745
|
+
clearTimeout(timer.current);
|
|
5858
5746
|
}
|
|
5747
|
+
};
|
|
5748
|
+
}, [focused, rest.label, rest.placeholder]);
|
|
5749
|
+
React__default.useEffect(function () {
|
|
5750
|
+
labeled.stopAnimation();
|
|
5751
|
+
// The label should be minimized if the text input is focused, or has text
|
|
5752
|
+
// In minimized mode, the label moves up and becomes small
|
|
5753
|
+
// workaround for animated regression for react native > 0.61
|
|
5754
|
+
// https://github.com/callstack/react-native-paper/pull/1440
|
|
5755
|
+
if (value || focused) {
|
|
5756
|
+
// minimize label
|
|
5757
|
+
Animated.timing(labeled, {
|
|
5758
|
+
toValue: 0,
|
|
5759
|
+
duration: BLUR_ANIMATION_DURATION * scale,
|
|
5760
|
+
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
5761
|
+
useNativeDriver: true,
|
|
5762
|
+
}).start();
|
|
5859
5763
|
}
|
|
5860
|
-
|
|
5764
|
+
else {
|
|
5765
|
+
// restore label
|
|
5766
|
+
Animated.timing(labeled, {
|
|
5767
|
+
toValue: 1,
|
|
5768
|
+
duration: FOCUS_ANIMATION_DURATION * scale,
|
|
5769
|
+
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
5770
|
+
useNativeDriver: true,
|
|
5771
|
+
}).start();
|
|
5772
|
+
}
|
|
5773
|
+
}, [focused, value, labeled, scale]);
|
|
5774
|
+
var onLeftAffixLayoutChange = React__default.useCallback(function (event) {
|
|
5775
|
+
var height = roundLayoutSize(event.nativeEvent.layout.height);
|
|
5776
|
+
var width = roundLayoutSize(event.nativeEvent.layout.width);
|
|
5777
|
+
if (width !== leftLayout.width || height !== leftLayout.height) {
|
|
5778
|
+
setLeftLayout({
|
|
5779
|
+
width: width,
|
|
5780
|
+
height: height,
|
|
5781
|
+
});
|
|
5782
|
+
}
|
|
5783
|
+
}, [leftLayout.height, leftLayout.width]);
|
|
5784
|
+
var onRightAffixLayoutChange = React__default.useCallback(function (event) {
|
|
5785
|
+
var width = roundLayoutSize(event.nativeEvent.layout.width);
|
|
5786
|
+
var height = roundLayoutSize(event.nativeEvent.layout.height);
|
|
5787
|
+
if (width !== rightLayout.width || height !== rightLayout.height) {
|
|
5788
|
+
setRightLayout({
|
|
5789
|
+
width: width,
|
|
5790
|
+
height: height,
|
|
5791
|
+
});
|
|
5792
|
+
}
|
|
5793
|
+
}, [rightLayout.height, rightLayout.width]);
|
|
5794
|
+
var handleFocus = function (args) {
|
|
5795
|
+
var _a;
|
|
5796
|
+
if (disabled || !editable) {
|
|
5797
|
+
return;
|
|
5798
|
+
}
|
|
5799
|
+
setFocused(true);
|
|
5800
|
+
(_a = rest.onFocus) === null || _a === void 0 ? void 0 : _a.call(rest, args);
|
|
5861
5801
|
};
|
|
5862
|
-
var
|
|
5863
|
-
|
|
5864
|
-
|
|
5802
|
+
var handleBlur = function (args) {
|
|
5803
|
+
var _a;
|
|
5804
|
+
if (!editable) {
|
|
5805
|
+
return;
|
|
5806
|
+
}
|
|
5807
|
+
setFocused(false);
|
|
5808
|
+
(_a = rest.onBlur) === null || _a === void 0 ? void 0 : _a.call(rest, args);
|
|
5809
|
+
};
|
|
5810
|
+
var handleChangeText = function (value) {
|
|
5811
|
+
var _a;
|
|
5812
|
+
if (!editable || disabled) {
|
|
5813
|
+
return;
|
|
5814
|
+
}
|
|
5815
|
+
if (!isControlled) {
|
|
5816
|
+
// Keep track of value in local state when input is not controlled
|
|
5817
|
+
setUncontrolledValue(value);
|
|
5818
|
+
}
|
|
5819
|
+
(_a = rest.onChangeText) === null || _a === void 0 ? void 0 : _a.call(rest, value);
|
|
5820
|
+
};
|
|
5821
|
+
var handleLayoutAnimatedText = React__default.useCallback(function (e) {
|
|
5822
|
+
var width = roundLayoutSize(e.nativeEvent.layout.width);
|
|
5823
|
+
var height = roundLayoutSize(e.nativeEvent.layout.height);
|
|
5824
|
+
if (width !== labelLayout.width || height !== labelLayout.height) {
|
|
5825
|
+
setLabelLayout({
|
|
5826
|
+
width: width,
|
|
5827
|
+
height: height,
|
|
5828
|
+
measured: true,
|
|
5829
|
+
});
|
|
5830
|
+
}
|
|
5831
|
+
}, [labelLayout.height, labelLayout.width]);
|
|
5832
|
+
var handleLabelTextLayout = React__default.useCallback(function (_a) {
|
|
5833
|
+
var nativeEvent = _a.nativeEvent;
|
|
5834
|
+
setLabelTextLayout({
|
|
5835
|
+
width: nativeEvent.lines.reduce(function (acc, line) { return acc + Math.ceil(line.width); }, 0),
|
|
5836
|
+
});
|
|
5837
|
+
}, []);
|
|
5838
|
+
var handleInputContainerLayout = React__default.useCallback(function (_a) {
|
|
5839
|
+
var layout = _a.nativeEvent.layout;
|
|
5840
|
+
setInputContainerLayout({
|
|
5841
|
+
width: layout.width,
|
|
5842
|
+
});
|
|
5843
|
+
}, []);
|
|
5844
|
+
var forceFocus = React__default.useCallback(function () { var _a; return (_a = root.current) === null || _a === void 0 ? void 0 : _a.focus(); }, []);
|
|
5845
|
+
var _s = rest.maxFontSizeMultiplier, maxFontSizeMultiplier = _s === void 0 ? 1.5 : _s;
|
|
5846
|
+
var scaledLabel = !!(value || focused);
|
|
5847
|
+
if (mode === "default") {
|
|
5848
|
+
return (React__default.createElement(TextInputDefault, __assign({ dense: dense, disabled: disabled, error: errorProp, multiline: multiline, editable: editable, render: render }, rest, { theme: theme, value: value, placeholderTextColor: placeholderTextColor, clearButton: clearButton, parentState: {
|
|
5849
|
+
labeled: labeled,
|
|
5850
|
+
error: error,
|
|
5851
|
+
focused: focused,
|
|
5852
|
+
displayPlaceholder: displayPlaceholder,
|
|
5853
|
+
value: value,
|
|
5854
|
+
labelTextLayout: labelTextLayout,
|
|
5855
|
+
labelLayout: labelLayout,
|
|
5856
|
+
leftLayout: leftLayout,
|
|
5857
|
+
rightLayout: rightLayout,
|
|
5858
|
+
inputContainerLayout: inputContainerLayout,
|
|
5859
|
+
}, innerRef: function (ref) {
|
|
5860
|
+
root.current = ref;
|
|
5861
|
+
}, onFocus: handleFocus, forceFocus: forceFocus, onBlur: handleBlur, allowFontScaling: false, onChangeText: handleChangeText, onLayoutAnimatedText: handleLayoutAnimatedText, onInputLayout: handleInputContainerLayout, onLabelTextLayout: handleLabelTextLayout, onLeftAffixLayoutChange: onLeftAffixLayoutChange, onRightAffixLayoutChange: onRightAffixLayoutChange, maxFontSizeMultiplier: maxFontSizeMultiplier, contentStyle: contentStyle, scaledLabel: scaledLabel })));
|
|
5862
|
+
}
|
|
5863
|
+
return (React__default.createElement(TextInputFlat, __assign({ dense: dense, disabled: disabled, error: errorProp, multiline: false, editable: editable, clearButton: clearButton, render: render }, rest, { theme: theme, value: value, parentState: {
|
|
5864
|
+
labeled: labeled,
|
|
5865
|
+
error: error,
|
|
5866
|
+
focused: focused,
|
|
5867
|
+
displayPlaceholder: displayPlaceholder,
|
|
5868
|
+
value: value,
|
|
5869
|
+
labelTextLayout: labelTextLayout,
|
|
5870
|
+
labelLayout: labelLayout,
|
|
5871
|
+
leftLayout: leftLayout,
|
|
5872
|
+
rightLayout: rightLayout,
|
|
5873
|
+
inputContainerLayout: inputContainerLayout,
|
|
5874
|
+
}, innerRef: function (ref) {
|
|
5875
|
+
root.current = ref;
|
|
5876
|
+
}, onFocus: handleFocus, forceFocus: forceFocus, onBlur: handleBlur, onInputLayout: handleInputContainerLayout, allowFontScaling: false, onChangeText: handleChangeText, onLayoutAnimatedText: handleLayoutAnimatedText, onLabelTextLayout: handleLabelTextLayout, onLeftAffixLayoutChange: onLeftAffixLayoutChange, onRightAffixLayoutChange: onRightAffixLayoutChange, maxFontSizeMultiplier: maxFontSizeMultiplier, contentStyle: contentStyle, scaledLabel: scaledLabel })));
|
|
5877
|
+
});
|
|
5878
|
+
// @component ./Adornment/TextInputIcon.tsx
|
|
5879
|
+
// @component ./Adornment/TextInputAffix.tsx
|
|
5880
|
+
// @ts-ignore Types of property 'theme' are incompatible.
|
|
5881
|
+
TextInput.Affix = TextInputAffix;
|
|
5882
|
+
|
|
5883
|
+
var ScaleButton = function (_a) {
|
|
5884
|
+
var children = _a.children; _a.style; var _b = _a.onPress, onPress = _b === void 0 ? function () { } : _b, rest = __rest(_a, ["children", "style", "onPress"]);
|
|
5885
|
+
return (React__default.createElement(TouchableOpacity, __assign({}, rest, { onPress: onPress }), children));
|
|
5865
5886
|
};
|
|
5866
|
-
var
|
|
5887
|
+
var ScaleButton$1 = React__default.memo(ScaleButton);
|
|
5867
5888
|
|
|
5868
5889
|
var Button = function (_a) {
|
|
5869
5890
|
var style = _a.style, title = _a.title, borderColor = _a.borderColor, isLoading = _a.isLoading, left = _a.left, right = _a.right, small = _a.small, textStyle = _a.textStyle, onPress = _a.onPress, disabled = _a.disabled, backgroundColor = _a.backgroundColor, textColor = _a.textColor, _b = _a.bold, bold = _b === void 0 ? true : _b, _c = _a.size, size = _c === void 0 ? 16 : _c, _d = _a.medium, medium = _d === void 0 ? false : _d, _e = _a.mode, mode = _e === void 0 ? "contained" : _e; _a.theme; var props = __rest(_a, ["style", "title", "borderColor", "isLoading", "left", "right", "small", "textStyle", "onPress", "disabled", "backgroundColor", "textColor", "bold", "size", "medium", "mode", "theme"]);
|