• 카테고리

    질문 & 답변
  • 세부 분야

    모바일 앱 개발

  • 해결 여부

    미해결

9.4 왜 DisplayName이 한글자밖에 안찍힐까요?

23.05.11 12:52 작성 23.05.11 12:55 수정 조회수 163

0

프로필 수정하는 부분에서

DisplayName을 넣어서 바꿔보면

 

맨첫 한글자만 가져오게 되는데

 

setDisplayName이 말을 안듣는 것인지...

뭐가 문제인건지 모르겠네요...

 

코드 확인한번만 해주시면 감사하겠습니다.

import { StyleSheet, Text, View, Button, Pressable, TextInput, Keyboard, Alert } from 'react-native';
import PropTypes from 'prop-types';
import { useNavigation } from '@react-navigation/native';
import { useUserState } from '../contexts/UserContext';
import FastImage from '../components/FastImage';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { GRAY, WHITE } from '../colors';
import HeaderRight from './../components/HeaderRight';
import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
import { updateUserInfo } from '../api/auth';
import SafeInputView from '../components/SafeInputView';

const UpdateProfileScreen = () => {
    const navigation = useNavigation();

    const [user, setUser] = useUserState();
    const [displayName, setDisplayName] = useState(user.displayName);
    const [disabled, setDisabled] = useState(true);
    const [isLoading, setIsLoading] = useState(false);

    const onSubmit = useCallback(async () => {
        Keyboard.dismiss();
        if (!disabled) {
            setIsLoading(true);
            try {
                const userInfo = { displayName };
                console.log(userInfo);
                await updateUserInfo(userInfo);
                setUser((prev) => ({ ...prev, ...userInfo }));
                // navigation.goBack();
                setIsLoading(false);
            } catch (error) {
                Alert.alert('사용자 수정 실패', error.message);
                setIsLoading(false);
            }
        }
    }, [disabled, displayName, navigation, setUser]);

    useEffect(() => {
        setDisabled(!displayName || isLoading);
        console.log('current', displayName);
    }, [displayName, isLoading]);

    useLayoutEffect(() => {
        navigation.setOptions({
            headerRight: () => <HeaderRight onPress={onSubmit} disabled={disabled} />,
        });
    }, [navigation, disabled]);

    return (
        <SafeInputView>
            <View style={styles.container}>
                <View>
                    <View>
                        <FastImage source={{ uri: user.photoURL }} style={styles.photo}></FastImage>
                        <Pressable onPress={() => {}} style={styles.imageButton}>
                            <MaterialCommunityIcons name="image" size={20} color={WHITE} />
                        </Pressable>
                    </View>
                    <TextInput
                        value={displayName}
                        onChangeText={(text) => setDisplayName(text.trim())}
                        style={styles.input}
                        placeholder="NickName"
                        textAlign="center"
                        maxLength={10}
                        returnKeyType="done"
                        autoCapitalize="none"
                        autoCorrect={false}
                        textContentType="none"
                    />
                </View>
            </View>
        </SafeInputView>
    );
};

답변 1

답변을 작성해보세요.

0

안녕하세요,

 

질문을 할 때 프로젝트 전체 코드를 깃헙에 올리고 레포 링크와 함께 상세한 상황설명을 함께 남겨주세요.

그래야 정확한 확인이 가능합니다.

 

닉네임을 변경하기 위해 화면에서 닉네임을 입력하면 첫 글자만 나타난다는 얘기인가요?

올려주신 코드를 봤을때는 특별히 오타나 문제가 보이지 않습니다.

 

코드 전체를 올려주시면 조금 더 확인해 보겠습니다.

추가로 문제가 발생한 상황에서 어떤 값을 입력했는지도 함께 알려주세요.

감사합니다.