【问题标题】:Is there a way to modify the label prop from the gifted-chat component?有没有办法从有天赋的聊天组件中修改标签道具?
【发布时间】:2019-11-10 20:31:29
【问题描述】:

我正在使用 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,
  }

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

loadEarlier={true}
          isLoadingEarlier={false}

我想知道是否可以通过某种方式访问​​该标签以将“加载早期消息”修改为另一种语言。我想不通。

【问题讨论】:

    标签: react-native components


    【解决方案1】:

    看来您应该使用 renderLoadEarlier 属性来呈现带有自定义标签的 <LoadEarlier> 按钮。

    导入它-

    import { LoadEarlier } from 'react-native-gifted-chat';
    

    然后在渲染中 -

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

    希望对你有帮助

    【讨论】:

    • 优秀。谢谢! ?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-31
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多