* feature edit profile screen * minor refactoring * Apply suggestions from code review Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * ts fixes * revert floatingTextInput label This reverts commit a778e1f76191aea7c1a18d60a23ffbd6d3dec0eb. * code clean up * Apply suggestions from code review Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * code fix * code fix * Adding preventDoubleTap * rename id to fieldKey * Update edit_profile.tsx * wip * navigating through fields; partly done * navigating through fields - partly done * navigating through fields; partly done * completed field navigation * added theme into dependency array * code clean up * revert conditions for disabling fields * Added colorFilters prop to Loading component * Completed loading feature on Edit Profile screen * code clean up * Add profile_error * renamed valid_mime_types to valid_image_mime_types * added props isDisabled to email field * refactored next field logic * fix * fix * code clean up * code clean up * Updated ESLINT hook rules to warning instead of disabled * code fix * code fix * new line within your_profile component * added memo for Field component * added canSave to dependency array * update loading component - color filter * Update app/screens/edit_profile/edit_profile.tsx Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * dependency fix * fix to fetch my latest status * fix to remove unnecessary user id for local action updateLocalUser * prevents bouncing for iOS * code revert * Adding textInputStyle and animatedTextStyle to FloatingTextInput component * correction after dev session * adding changes as per new ux * Update edit_profile.tsx * corrections after ux review * ux review * ux review * code clean up * Adding userProfileFields into useMemo * Add enableSaveButton to dependency of submitUser * Revert fetching status on userProfile * EditProfile enable extraScrollHeight on iOS only Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
103 lines
3.2 KiB
TypeScript
103 lines
3.2 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {memo, RefObject, useCallback} from 'react';
|
|
import {useIntl} from 'react-intl';
|
|
import {Platform, StyleSheet, TextInputProps, View} from 'react-native';
|
|
|
|
import FloatingTextInput, {FloatingTextInputRef} from '@components/floating_text_input_label';
|
|
import {useTheme} from '@context/theme';
|
|
import {useIsTablet} from '@hooks/device';
|
|
import {changeOpacity, getKeyboardAppearanceFromTheme, makeStyleSheetFromTheme} from '@utils/theme';
|
|
|
|
export type FieldProps = TextInputProps & {
|
|
isDisabled?: boolean;
|
|
fieldKey: string;
|
|
label: string;
|
|
maxLength?: number;
|
|
onTextChange: (fieldKey: string, value: string) => void;
|
|
isOptional?: boolean;
|
|
testID: string;
|
|
value: string;
|
|
fieldRef: RefObject<FloatingTextInputRef>;
|
|
onFocusNextField: (fieldKey: string) => void;
|
|
};
|
|
|
|
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
|
|
return StyleSheet.create({
|
|
viewContainer: {
|
|
marginVertical: 8,
|
|
alignItems: 'center',
|
|
width: '100%',
|
|
},
|
|
disabledStyle: {
|
|
backgroundColor: changeOpacity(theme.centerChannelColor, 0.04),
|
|
},
|
|
});
|
|
});
|
|
|
|
const Field = ({
|
|
autoCapitalize = 'none',
|
|
autoCorrect = false,
|
|
fieldKey,
|
|
isDisabled = false,
|
|
isOptional = false,
|
|
keyboardType = 'default',
|
|
label,
|
|
maxLength,
|
|
onTextChange,
|
|
testID,
|
|
value,
|
|
fieldRef,
|
|
onFocusNextField,
|
|
...props
|
|
}: FieldProps) => {
|
|
const theme = useTheme();
|
|
const intl = useIntl();
|
|
const isTablet = useIsTablet();
|
|
|
|
const onChangeText = useCallback((text: string) => onTextChange(fieldKey, text), [fieldKey, onTextChange]);
|
|
|
|
const onSubmitEditing = useCallback(() => {
|
|
onFocusNextField(fieldKey);
|
|
}, [fieldKey, onFocusNextField]);
|
|
|
|
const style = getStyleSheet(theme);
|
|
|
|
const keyboard = (Platform.OS === 'android' && keyboardType === 'url') ? 'default' : keyboardType;
|
|
|
|
const optionalText = intl.formatMessage({id: 'channel_modal.optional', defaultMessage: '(optional)'});
|
|
|
|
const formattedLabel = isOptional ? `${label} ${optionalText}` : label;
|
|
|
|
const textInputStyle = isDisabled ? style.disabledStyle : undefined;
|
|
const subContainer = [style.viewContainer, {paddingHorizontal: isTablet ? 42 : 20}];
|
|
|
|
return (
|
|
<View
|
|
testID={testID}
|
|
style={subContainer}
|
|
>
|
|
<FloatingTextInput
|
|
autoCapitalize={autoCapitalize}
|
|
autoCorrect={autoCorrect}
|
|
disableFullscreenUI={true}
|
|
editable={!isDisabled}
|
|
keyboardAppearance={getKeyboardAppearanceFromTheme(theme)}
|
|
keyboardType={keyboard}
|
|
label={formattedLabel}
|
|
maxLength={maxLength}
|
|
onChangeText={onChangeText}
|
|
testID={`${testID}.input`}
|
|
theme={theme}
|
|
value={value}
|
|
ref={fieldRef}
|
|
onSubmitEditing={onSubmitEditing}
|
|
textInputStyle={textInputStyle}
|
|
{...props}
|
|
/>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
export default memo(Field);
|