有没有办法修改有天赋的聊天组件中的 label 属性?

3 components react-native

我正在使用 Gifted Chat https://github.com/FaridSafi/react-native-gifted-chat/但我需要一些标签采用另一种语言,即此处找到的 LoadEarlier 标签:https: //github.com/FaridSafi /react-native-gifted-chat/blob/master/src/LoadEarlier.tsx

此处定义:

  static defaultProps = {
    onLoadEarlier: () => {},
    isLoadingEarlier: false,
    label: 'Load earlier messages',
    containerStyle: {},
    wrapperStyle: {},
    textStyle: {},
    activityIndicatorStyle: {},
    activityIndicatorColor: 'white',
    activityIndicatorSize: 'small',
  }

  static propTypes = {
    onLoadEarlier: PropTypes.func,
    isLoadingEarlier: PropTypes.bool,
    label: PropTypes.string,
    containerStyle: ViewPropTypes.style,
    wrapperStyle: ViewPropTypes.style,
    textStyle: PropTypes.any,
    activityIndicatorStyle: ViewPropTypes.style,
    activityIndicatorColor: PropTypes.string,
    activityIndicatorSize: PropTypes.string,
  }
Run Code Online (Sandbox Code Playgroud)

我通过导入组件来使用聊天react-native-gifted-chat,然后将其用作<GiftedChat />它所具有的道具的一部分:

loadEarlier={true}
          isLoadingEarlier={false}
Run Code Online (Sandbox Code Playgroud)

我想知道是否有某种方法可以到达该标签以将“加载较早的消息”修改为另一种语言。我想不通。

小智 5

看起来您应该使用renderLoadEarlierprop 来渲染<LoadEarlier>带有自定义标签的按钮。

导入它-

import { LoadEarlier } from 'react-native-gifted-chat';
Run Code Online (Sandbox Code Playgroud)

然后在渲染中 -

    render() {

        const myLoadEarlier = (props) => <LoadEarlier {...props} label="Custom Load Earlier Label" />;

        return(
            <View>
                ...
                <GiftedChat
                    ...
                    renderLoadEarlier={myLoadEarlier}
                />
            </View>
        );
   }

Run Code Online (Sandbox Code Playgroud)

希望这可以帮助