mattermost-mobile-upstream/app/components/floating_input/floating_text_input_label.tsx
Pablo Vélez 4d842026f6
Some checks failed
ci / lint-typecheck (push) Has been cancelled
ci / detox-lint-typecheck (push) Has been cancelled
ci / test (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Mm 70564 channel labels use in channel creation (#10146)
* MM-70516 - Add ability to edit channel attribute values from Channel Info

* Add API methods for patching property fields and setting channel attribute requirements

* Update channel attribute clearing behavior for required and non-required fields

* MM-70564 - use channel attributes on channel creation

* Fix undefined propertyValues and ternary formatting in channel attributes

* Fix spelling of "colour" to "color" in attribute chip tests and related comments

* Add visibility checks for channel attribute labels in tests

* Fix data-integrity, permission, and accessibility issues in channel attributes: scoped pruning, atomic writes, race serialization, required clear/stale-option guards

* Fix handling of null values in apiGetChannelAttributeValue and update test assertions for channel attributes

* Improve channel attribute editor sizing for long labels, keep Save visible, and prevent keyboard overlap on Android

* Address CodeRabbit feedback for nullable values, bottom-sheet state, async validation, and reliable E2E cleanup

* lock-safe field fetch, create-time gate recheck, scoped value pruning, and tappable header chips

* Address CodeRabbit feedback: drop queued attribute saves on channel switch and use page object selectors in E2E

* Respect the ChannelAttributesRequired flag on channel creation and enable it for channel attribute E2E

* Skip required channel attribute E2E tests and stop enabling ChannelAttributesRequired on the shared server until  they move to SITE_3

* Fix clearing channel attributes on iOS by sending an empty value instead of null, and stop E2E suites from turning  off the ChannelAttributes flag mid-run

* Refactor getEmptyPropertyValue to accept string type for fieldType parameter

* E2E: give channel attribute test fields a suite-unique suffix

Pool shards may only create optional property fields named <name>_<6 hex>; fixed names were blocked by the pool guard.

* E2E: restore channel attribute cleanup checks; name network error codes

Brings back the PR's afterEach/afterAll error handling that the main merge replaced, and makes a no-response error show its codes (an AggregateError has an empty message).

* E2E: run channel attribute creation and editing specs on server B

Their 11 required-attribute tests could not run on the shared servers. Both specs now run on the mutation server with ChannelAttributesRequired on for their run, and the tests are re-enabled. setChannelAttributesRequired moves to the shared helper.

* Check header chips instead of their wrapper and use toExist for the create screen in channel attribute E2E

---------

Co-authored-by: yasserfaraazkhan <attitude3cena.yf@gmail.com>
2026-10-30 15:03:55 +01:00

198 lines
6.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// Note: This file has been adapted from the library https://github.com/csath/react-native-reanimated-text-input
import {RUNNING_E2E} from '@env';
import {BottomSheetTextInput} from '@gorhom/bottom-sheet';
import React, {useState, useRef, useImperativeHandle, forwardRef, useMemo, useCallback} from 'react';
import {type LayoutChangeEvent, type NativeSyntheticEvent, type StyleProp, type TargetedEvent, TextInput, type TextInputFocusEventData, type TextInputProps, type TextStyle} from 'react-native';
import {changeOpacity, getKeyboardAppearanceFromTheme, makeStyleSheetFromTheme} from '@utils/theme';
import {typography} from '@utils/typography';
import FloatingInputContainer from './floating_input_container';
import {onExecution} from './utils';
const DEFAULT_INPUT_HEIGHT = 48;
// Expose the input's value to the accessibility tree only in E2E builds so Maestro
// can read the typed value. Gated so real builds are byte-for-byte unchanged.
const isRunningE2e = RUNNING_E2E === 'true';
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
input: {
backgroundColor: 'transparent',
borderWidth: 0,
flex: 1,
paddingHorizontal: 0,
paddingTop: 0,
paddingBottom: 0,
flexDirection: 'row',
color: theme.centerChannelColor,
borderColor: changeOpacity(theme.centerChannelColor, 0.16),
borderRadius: 4,
...typography('Body', 200),
lineHeight: undefined,
},
}));
export type FloatingTextInputRef = {
blur: () => void;
focus: () => void;
isFocused: () => boolean;
}
type TextInputHandle = Pick<TextInput, 'blur' | 'focus' | 'isFocused'>;
type FloatingTextInputProps = /*TextInputProps &*/ {
bottomSheetInput?: boolean;
editable?: boolean;
endAdornment?: React.ReactNode;
error?: string;
errorIcon?: string;
label: string;
multiline?: boolean;
multilineInputHeight?: number;
onBlur?: (event: NativeSyntheticEvent<TargetedEvent>) => void;
onFocus?: (e: NativeSyntheticEvent<TargetedEvent>) => void;
onLayout?: (e: LayoutChangeEvent) => void;
placeholder?: string;
hideErrorIcon?: boolean;
testID?: string;
theme: Theme;
value?: string;
rawInput?: boolean;
onChangeText?: TextInputProps['onChangeText'];
defaultValue?: TextInputProps['defaultValue'];
autoFocus?: TextInputProps['autoFocus'];
enablesReturnKeyAutomatically?: TextInputProps['enablesReturnKeyAutomatically'];
keyboardType?: TextInputProps['keyboardType'];
onSubmitEditing?: TextInputProps['onSubmitEditing'];
returnKeyType?: TextInputProps['returnKeyType'];
secureTextEntry?: TextInputProps['secureTextEntry'];
blurOnSubmit?: TextInputProps['blurOnSubmit'];
autoComplete?: TextInputProps['autoComplete'];
disableFullscreenUI?: TextInputProps['disableFullscreenUI'];
maxLength?: TextInputProps['maxLength'];
}
const FloatingTextInput = forwardRef<FloatingTextInputRef, FloatingTextInputProps>(({
bottomSheetInput = false,
editable = true,
error,
endAdornment,
label = '',
multiline,
multilineInputHeight,
onBlur,
onFocus,
onLayout,
placeholder,
hideErrorIcon = false,
testID,
theme,
value,
rawInput = false,
...textInputProps
}: FloatingTextInputProps, ref) => {
const [focused, setIsFocused] = useState(false);
const focusedLabel = Boolean(focused || Boolean(value) || placeholder);
const inputRef = useRef<TextInputHandle>(null);
const styles = getStyleSheet(theme);
const setInputRef = useCallback((instance: TextInputHandle | null | undefined) => {
inputRef.current = instance ?? null;
}, []);
useImperativeHandle(ref, () => ({
blur: () => inputRef.current?.blur(),
focus: () => inputRef.current?.focus(),
isFocused: () => inputRef.current?.isFocused() || false,
}), [inputRef]);
const onTextInputBlur = useCallback((e: NativeSyntheticEvent<TextInputFocusEventData>) => onExecution(e,
() => {
setIsFocused(false);
},
onBlur,
), [onBlur]);
const onTextInputFocus = useCallback((e: NativeSyntheticEvent<TextInputFocusEventData>) => onExecution(e,
() => {
setIsFocused(true);
},
onFocus,
), [onFocus]);
const defaultHeight = multiline ? multilineInputHeight || 100 : DEFAULT_INPUT_HEIGHT;
const combinedTextInputStyle = useMemo(() => {
const res: StyleProp<TextStyle> = [styles.input];
if (multiline) {
const height = multilineInputHeight ? multilineInputHeight - 20 : 80;
res.push({height, textAlignVertical: 'top'});
}
return res;
}, [styles, multiline, multilineInputHeight]);
const focus = useCallback(() => {
inputRef.current?.focus();
}, []);
const inputProps: TextInputProps = {
...textInputProps,
editable,
style: combinedTextInputStyle,
placeholder,
placeholderTextColor: changeOpacity(theme.centerChannelColor, 0.64),
multiline,
textAlignVertical: 'top',
value,
accessibilityValue: isRunningE2e ? {text: value} : undefined,
onFocus: onTextInputFocus,
onBlur: onTextInputBlur,
underlineColorAndroid: 'transparent',
testID,
keyboardAppearance: getKeyboardAppearanceFromTheme(theme),
autoCorrect: !rawInput,
autoCapitalize: rawInput ? 'none' : undefined,
};
return (
<FloatingInputContainer
hasValue={Boolean(value)}
defaultHeight={defaultHeight}
onLayout={onLayout}
label={label}
error={error}
hideErrorIcon={hideErrorIcon}
theme={theme}
focus={focus}
focused={focused}
focusedLabel={focusedLabel}
editable={editable}
testID={testID || 'floating-text-input-label'}
>
{bottomSheetInput ? (
<BottomSheetTextInput
{...inputProps}
ref={setInputRef}
/>
) : (
<TextInput
{...inputProps}
ref={setInputRef}
/>
)}
{endAdornment}
</FloatingInputContainer>
);
});
FloatingTextInput.displayName = 'FloatingTextInput';
export default FloatingTextInput;