【问题标题】:Card with FlatList React native带有 FlatList React Native 的卡片
【发布时间】:2021-08-16 03:36:42
【问题描述】:

我试图通过使用带有平面列表的卡片来实现消息视图我如何将平面列表的几个元素排列在左屏幕右屏幕上。

我希望绿卡在屏幕左侧

【问题讨论】:

  • 欢迎。你有你的renderItemdata 的例子吗?

标签: react-native react-native-flatlist


【解决方案1】:

您可以使用react-native-gifted-chat 来获得您想要的结果。

npm install react-native-gifted-chat --save

import React, { useState, useCallback, useEffect } from 'react'
import { GiftedChat } from 'react-native-gifted-chat'

export function Example() {
  const [messages, setMessages] = useState([]);

  useEffect(() => {
    setMessages([
      {
        _id: 1,
        text: 'Hello developer',
        createdAt: new Date(),
        user: {
          _id: 2,
          name: 'React Native',
          avatar: 'https://placeimg.com/140/140/any',
        },
      },
    ])
  }, [])

  const onSend = useCallback((messages = []) => {
    setMessages(previousMessages => GiftedChat.append(previousMessages, messages))
  }, [])

  return (
    <GiftedChat
      messages={messages}
      onSend={messages => onSend(messages)}
      user={{
        _id: 1,
      }}
    />
  )
}

【讨论】:

  • 我正在尝试构建一个没有 react-native-gifted-chat 的自定义聊天应用程序。有天赋的聊天包非常简单。
  • 那么你必须分享你的 flatlist 代码。
猜你喜欢
  • 2018-06-05
  • 2020-10-19
  • 2020-08-17
  • 2018-04-05
  • 2018-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多