@unif/react-native-chat 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +48 -0
- package/lib/module/actions/index.js +2 -0
- package/lib/module/actions/index.js.map +1 -0
- package/lib/module/actions/types.js +4 -0
- package/lib/module/actions/types.js.map +1 -0
- package/lib/module/components/Attachments/AttachmentItem.js +108 -0
- package/lib/module/components/Attachments/AttachmentItem.js.map +1 -0
- package/lib/module/components/Attachments/Attachments.js +60 -0
- package/lib/module/components/Attachments/Attachments.js.map +1 -0
- package/lib/module/components/Attachments/constants.js +18 -0
- package/lib/module/components/Attachments/constants.js.map +1 -0
- package/lib/module/components/Attachments/index.js +4 -0
- package/lib/module/components/Attachments/index.js.map +1 -0
- package/lib/module/components/Attachments/styles.js +83 -0
- package/lib/module/components/Attachments/styles.js.map +1 -0
- package/lib/module/components/Attachments/types.js +4 -0
- package/lib/module/components/Attachments/types.js.map +1 -0
- package/lib/module/components/Chat/Chat.js +29 -0
- package/lib/module/components/Chat/Chat.js.map +1 -0
- package/lib/module/components/Chat/index.js +4 -0
- package/lib/module/components/Chat/index.js.map +1 -0
- package/lib/module/components/Chat/styles.js +17 -0
- package/lib/module/components/Chat/styles.js.map +1 -0
- package/lib/module/components/Chat/types.js +4 -0
- package/lib/module/components/Chat/types.js.map +1 -0
- package/lib/module/components/Citation/Citation.js +32 -0
- package/lib/module/components/Citation/Citation.js.map +1 -0
- package/lib/module/components/Citation/index.js +4 -0
- package/lib/module/components/Citation/index.js.map +1 -0
- package/lib/module/components/Citation/styles.js +15 -0
- package/lib/module/components/Citation/styles.js.map +1 -0
- package/lib/module/components/Citation/types.js +2 -0
- package/lib/module/components/Citation/types.js.map +1 -0
- package/lib/module/components/Composer/Composer.js +149 -0
- package/lib/module/components/Composer/Composer.js.map +1 -0
- package/lib/module/components/Composer/constants.js +14 -0
- package/lib/module/components/Composer/constants.js.map +1 -0
- package/lib/module/components/Composer/index.js +4 -0
- package/lib/module/components/Composer/index.js.map +1 -0
- package/lib/module/components/Composer/styles.js +43 -0
- package/lib/module/components/Composer/styles.js.map +1 -0
- package/lib/module/components/Composer/types.js +4 -0
- package/lib/module/components/Composer/types.js.map +1 -0
- package/lib/module/components/Confirmation/Confirmation.js +56 -0
- package/lib/module/components/Confirmation/Confirmation.js.map +1 -0
- package/lib/module/components/Confirmation/constants.js +10 -0
- package/lib/module/components/Confirmation/constants.js.map +1 -0
- package/lib/module/components/Confirmation/index.js +4 -0
- package/lib/module/components/Confirmation/index.js.map +1 -0
- package/lib/module/components/Confirmation/styles.js +34 -0
- package/lib/module/components/Confirmation/styles.js.map +1 -0
- package/lib/module/components/Confirmation/types.js +4 -0
- package/lib/module/components/Confirmation/types.js.map +1 -0
- package/lib/module/components/Feedback/Feedback.js +82 -0
- package/lib/module/components/Feedback/Feedback.js.map +1 -0
- package/lib/module/components/Feedback/constants.js +15 -0
- package/lib/module/components/Feedback/constants.js.map +1 -0
- package/lib/module/components/Feedback/index.js +4 -0
- package/lib/module/components/Feedback/index.js.map +1 -0
- package/lib/module/components/Feedback/styles.js +30 -0
- package/lib/module/components/Feedback/styles.js.map +1 -0
- package/lib/module/components/Feedback/types.js +4 -0
- package/lib/module/components/Feedback/types.js.map +1 -0
- package/lib/module/components/Message/MarkdownContent/MarkdownContent.js +68 -0
- package/lib/module/components/Message/MarkdownContent/MarkdownContent.js.map +1 -0
- package/lib/module/components/Message/MarkdownContent/MarkdownImage/MarkdownImage.js +53 -0
- package/lib/module/components/Message/MarkdownContent/MarkdownImage/MarkdownImage.js.map +1 -0
- package/lib/module/components/Message/MarkdownContent/MarkdownImage/styles.js +10 -0
- package/lib/module/components/Message/MarkdownContent/MarkdownImage/styles.js.map +1 -0
- package/lib/module/components/Message/MarkdownContent/MarkdownImage/types.js +2 -0
- package/lib/module/components/Message/MarkdownContent/MarkdownImage/types.js.map +1 -0
- package/lib/module/components/Message/MarkdownContent/styles.js +85 -0
- package/lib/module/components/Message/MarkdownContent/styles.js.map +1 -0
- package/lib/module/components/Message/MarkdownContent/types.js +2 -0
- package/lib/module/components/Message/MarkdownContent/types.js.map +1 -0
- package/lib/module/components/Message/Message.js +87 -0
- package/lib/module/components/Message/Message.js.map +1 -0
- package/lib/module/components/Message/constants.js +4 -0
- package/lib/module/components/Message/constants.js.map +1 -0
- package/lib/module/components/Message/index.js +4 -0
- package/lib/module/components/Message/index.js.map +1 -0
- package/lib/module/components/Message/isNestedAction.js +14 -0
- package/lib/module/components/Message/isNestedAction.js.map +1 -0
- package/lib/module/components/Message/styles.js +73 -0
- package/lib/module/components/Message/styles.js.map +1 -0
- package/lib/module/components/Message/types.js +4 -0
- package/lib/module/components/Message/types.js.map +1 -0
- package/lib/module/components/MessageList/MessageList.js +223 -0
- package/lib/module/components/MessageList/MessageList.js.map +1 -0
- package/lib/module/components/MessageList/constants.js +4 -0
- package/lib/module/components/MessageList/constants.js.map +1 -0
- package/lib/module/components/MessageList/index.js +4 -0
- package/lib/module/components/MessageList/index.js.map +1 -0
- package/lib/module/components/MessageList/styles.js +20 -0
- package/lib/module/components/MessageList/styles.js.map +1 -0
- package/lib/module/components/MessageList/types.js +4 -0
- package/lib/module/components/MessageList/types.js.map +1 -0
- package/lib/module/components/MessageList/webPrependAnchor/constants.js +4 -0
- package/lib/module/components/MessageList/webPrependAnchor/constants.js.map +1 -0
- package/lib/module/components/MessageList/webPrependAnchor/index.js +4 -0
- package/lib/module/components/MessageList/webPrependAnchor/index.js.map +1 -0
- package/lib/module/components/MessageList/webPrependAnchor/types.js +4 -0
- package/lib/module/components/MessageList/webPrependAnchor/types.js.map +1 -0
- package/lib/module/components/MessageList/webPrependAnchor/useWebPrependAnchor.js +19 -0
- package/lib/module/components/MessageList/webPrependAnchor/useWebPrependAnchor.js.map +1 -0
- package/lib/module/components/MessageList/webPrependAnchor/useWebPrependAnchor.web.js +208 -0
- package/lib/module/components/MessageList/webPrependAnchor/useWebPrependAnchor.web.js.map +1 -0
- package/lib/module/components/Process/Process.js +121 -0
- package/lib/module/components/Process/Process.js.map +1 -0
- package/lib/module/components/Process/constants.js +17 -0
- package/lib/module/components/Process/constants.js.map +1 -0
- package/lib/module/components/Process/index.js +4 -0
- package/lib/module/components/Process/index.js.map +1 -0
- package/lib/module/components/Process/styles.js +77 -0
- package/lib/module/components/Process/styles.js.map +1 -0
- package/lib/module/components/Process/types.js +4 -0
- package/lib/module/components/Process/types.js.map +1 -0
- package/lib/module/components/Sources/Sources.js +64 -0
- package/lib/module/components/Sources/Sources.js.map +1 -0
- package/lib/module/components/Sources/constants.js +4 -0
- package/lib/module/components/Sources/constants.js.map +1 -0
- package/lib/module/components/Sources/index.js +4 -0
- package/lib/module/components/Sources/index.js.map +1 -0
- package/lib/module/components/Sources/styles.js +52 -0
- package/lib/module/components/Sources/styles.js.map +1 -0
- package/lib/module/components/Sources/types.js +4 -0
- package/lib/module/components/Sources/types.js.map +1 -0
- package/lib/module/components/Suggestions/Suggestions.js +31 -0
- package/lib/module/components/Suggestions/Suggestions.js.map +1 -0
- package/lib/module/components/Suggestions/index.js +4 -0
- package/lib/module/components/Suggestions/index.js.map +1 -0
- package/lib/module/components/Suggestions/styles.js +18 -0
- package/lib/module/components/Suggestions/styles.js.map +1 -0
- package/lib/module/components/Suggestions/types.js +4 -0
- package/lib/module/components/Suggestions/types.js.map +1 -0
- package/lib/module/index.js +14 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/actions/index.d.ts +2 -0
- package/lib/typescript/src/actions/index.d.ts.map +1 -0
- package/lib/typescript/src/actions/types.d.ts +11 -0
- package/lib/typescript/src/actions/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Attachments/AttachmentItem.d.ts +3 -0
- package/lib/typescript/src/components/Attachments/AttachmentItem.d.ts.map +1 -0
- package/lib/typescript/src/components/Attachments/Attachments.d.ts +3 -0
- package/lib/typescript/src/components/Attachments/Attachments.d.ts.map +1 -0
- package/lib/typescript/src/components/Attachments/constants.d.ts +13 -0
- package/lib/typescript/src/components/Attachments/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/Attachments/index.d.ts +3 -0
- package/lib/typescript/src/components/Attachments/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Attachments/styles.d.ts +80 -0
- package/lib/typescript/src/components/Attachments/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Attachments/types.d.ts +34 -0
- package/lib/typescript/src/components/Attachments/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Chat/Chat.d.ts +3 -0
- package/lib/typescript/src/components/Chat/Chat.d.ts.map +1 -0
- package/lib/typescript/src/components/Chat/index.d.ts +3 -0
- package/lib/typescript/src/components/Chat/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Chat/styles.d.ts +15 -0
- package/lib/typescript/src/components/Chat/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Chat/types.d.ts +12 -0
- package/lib/typescript/src/components/Chat/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Citation/Citation.d.ts +3 -0
- package/lib/typescript/src/components/Citation/Citation.d.ts.map +1 -0
- package/lib/typescript/src/components/Citation/index.d.ts +3 -0
- package/lib/typescript/src/components/Citation/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Citation/styles.d.ts +12 -0
- package/lib/typescript/src/components/Citation/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Citation/types.d.ts +8 -0
- package/lib/typescript/src/components/Citation/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Composer/Composer.d.ts +4 -0
- package/lib/typescript/src/components/Composer/Composer.d.ts.map +1 -0
- package/lib/typescript/src/components/Composer/constants.d.ts +12 -0
- package/lib/typescript/src/components/Composer/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/Composer/index.d.ts +3 -0
- package/lib/typescript/src/components/Composer/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Composer/styles.d.ts +40 -0
- package/lib/typescript/src/components/Composer/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Composer/types.d.ts +53 -0
- package/lib/typescript/src/components/Composer/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Confirmation/Confirmation.d.ts +3 -0
- package/lib/typescript/src/components/Confirmation/Confirmation.d.ts.map +1 -0
- package/lib/typescript/src/components/Confirmation/constants.d.ts +5 -0
- package/lib/typescript/src/components/Confirmation/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/Confirmation/index.d.ts +3 -0
- package/lib/typescript/src/components/Confirmation/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Confirmation/styles.d.ts +31 -0
- package/lib/typescript/src/components/Confirmation/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Confirmation/types.d.ts +19 -0
- package/lib/typescript/src/components/Confirmation/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Feedback/Feedback.d.ts +3 -0
- package/lib/typescript/src/components/Feedback/Feedback.d.ts.map +1 -0
- package/lib/typescript/src/components/Feedback/constants.d.ts +5 -0
- package/lib/typescript/src/components/Feedback/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/Feedback/index.d.ts +3 -0
- package/lib/typescript/src/components/Feedback/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Feedback/styles.d.ts +27 -0
- package/lib/typescript/src/components/Feedback/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Feedback/types.d.ts +12 -0
- package/lib/typescript/src/components/Feedback/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/MarkdownContent/MarkdownContent.d.ts +3 -0
- package/lib/typescript/src/components/Message/MarkdownContent/MarkdownContent.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/MarkdownContent/MarkdownImage/MarkdownImage.d.ts +3 -0
- package/lib/typescript/src/components/Message/MarkdownContent/MarkdownImage/MarkdownImage.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/MarkdownContent/MarkdownImage/styles.d.ts +7 -0
- package/lib/typescript/src/components/Message/MarkdownContent/MarkdownImage/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/MarkdownContent/MarkdownImage/types.d.ts +9 -0
- package/lib/typescript/src/components/Message/MarkdownContent/MarkdownImage/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/MarkdownContent/styles.d.ts +92 -0
- package/lib/typescript/src/components/Message/MarkdownContent/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/MarkdownContent/types.d.ts +5 -0
- package/lib/typescript/src/components/Message/MarkdownContent/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/Message.d.ts +3 -0
- package/lib/typescript/src/components/Message/Message.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/constants.d.ts +2 -0
- package/lib/typescript/src/components/Message/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/index.d.ts +3 -0
- package/lib/typescript/src/components/Message/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/isNestedAction.d.ts +3 -0
- package/lib/typescript/src/components/Message/isNestedAction.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/styles.d.ts +70 -0
- package/lib/typescript/src/components/Message/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Message/types.d.ts +44 -0
- package/lib/typescript/src/components/Message/types.d.ts.map +1 -0
- package/lib/typescript/src/components/MessageList/MessageList.d.ts +4 -0
- package/lib/typescript/src/components/MessageList/MessageList.d.ts.map +1 -0
- package/lib/typescript/src/components/MessageList/constants.d.ts +2 -0
- package/lib/typescript/src/components/MessageList/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/MessageList/index.d.ts +3 -0
- package/lib/typescript/src/components/MessageList/index.d.ts.map +1 -0
- package/lib/typescript/src/components/MessageList/styles.d.ts +16 -0
- package/lib/typescript/src/components/MessageList/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/MessageList/types.d.ts +36 -0
- package/lib/typescript/src/components/MessageList/types.d.ts.map +1 -0
- package/lib/typescript/src/components/MessageList/webPrependAnchor/constants.d.ts +2 -0
- package/lib/typescript/src/components/MessageList/webPrependAnchor/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/MessageList/webPrependAnchor/index.d.ts +3 -0
- package/lib/typescript/src/components/MessageList/webPrependAnchor/index.d.ts.map +1 -0
- package/lib/typescript/src/components/MessageList/webPrependAnchor/types.d.ts +72 -0
- package/lib/typescript/src/components/MessageList/webPrependAnchor/types.d.ts.map +1 -0
- package/lib/typescript/src/components/MessageList/webPrependAnchor/useWebPrependAnchor.d.ts +3 -0
- package/lib/typescript/src/components/MessageList/webPrependAnchor/useWebPrependAnchor.d.ts.map +1 -0
- package/lib/typescript/src/components/MessageList/webPrependAnchor/useWebPrependAnchor.web.d.ts +3 -0
- package/lib/typescript/src/components/MessageList/webPrependAnchor/useWebPrependAnchor.web.d.ts.map +1 -0
- package/lib/typescript/src/components/Process/Process.d.ts +3 -0
- package/lib/typescript/src/components/Process/Process.d.ts.map +1 -0
- package/lib/typescript/src/components/Process/constants.d.ts +5 -0
- package/lib/typescript/src/components/Process/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/Process/index.d.ts +3 -0
- package/lib/typescript/src/components/Process/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Process/styles.d.ts +74 -0
- package/lib/typescript/src/components/Process/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Process/types.d.ts +32 -0
- package/lib/typescript/src/components/Process/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Sources/Sources.d.ts +3 -0
- package/lib/typescript/src/components/Sources/Sources.d.ts.map +1 -0
- package/lib/typescript/src/components/Sources/constants.d.ts +2 -0
- package/lib/typescript/src/components/Sources/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/Sources/index.d.ts +3 -0
- package/lib/typescript/src/components/Sources/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Sources/styles.d.ts +49 -0
- package/lib/typescript/src/components/Sources/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Sources/types.d.ts +16 -0
- package/lib/typescript/src/components/Sources/types.d.ts.map +1 -0
- package/lib/typescript/src/components/Suggestions/Suggestions.d.ts +3 -0
- package/lib/typescript/src/components/Suggestions/Suggestions.d.ts.map +1 -0
- package/lib/typescript/src/components/Suggestions/index.d.ts +3 -0
- package/lib/typescript/src/components/Suggestions/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Suggestions/styles.d.ts +14 -0
- package/lib/typescript/src/components/Suggestions/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/Suggestions/types.d.ts +18 -0
- package/lib/typescript/src/components/Suggestions/types.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +24 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +178 -0
- package/src/actions/index.ts +1 -0
- package/src/actions/types.ts +11 -0
- package/src/components/Attachments/AttachmentItem.tsx +139 -0
- package/src/components/Attachments/Attachments.tsx +72 -0
- package/src/components/Attachments/constants.ts +21 -0
- package/src/components/Attachments/index.ts +6 -0
- package/src/components/Attachments/styles.ts +54 -0
- package/src/components/Attachments/types.ts +38 -0
- package/src/components/Chat/Chat.tsx +26 -0
- package/src/components/Chat/index.ts +2 -0
- package/src/components/Chat/styles.ts +12 -0
- package/src/components/Chat/types.ts +11 -0
- package/src/components/Citation/Citation.tsx +33 -0
- package/src/components/Citation/index.ts +2 -0
- package/src/components/Citation/styles.ts +15 -0
- package/src/components/Citation/types.ts +7 -0
- package/src/components/Composer/Composer.tsx +208 -0
- package/src/components/Composer/constants.ts +11 -0
- package/src/components/Composer/index.ts +11 -0
- package/src/components/Composer/styles.ts +25 -0
- package/src/components/Composer/types.ts +61 -0
- package/src/components/Confirmation/Confirmation.tsx +63 -0
- package/src/components/Confirmation/constants.ts +12 -0
- package/src/components/Confirmation/index.ts +2 -0
- package/src/components/Confirmation/styles.ts +39 -0
- package/src/components/Confirmation/types.ts +21 -0
- package/src/components/Feedback/Feedback.tsx +87 -0
- package/src/components/Feedback/constants.ts +16 -0
- package/src/components/Feedback/index.ts +2 -0
- package/src/components/Feedback/styles.ts +30 -0
- package/src/components/Feedback/types.ts +13 -0
- package/src/components/Message/MarkdownContent/MarkdownContent.tsx +70 -0
- package/src/components/Message/MarkdownContent/MarkdownImage/MarkdownImage.tsx +52 -0
- package/src/components/Message/MarkdownContent/MarkdownImage/styles.ts +4 -0
- package/src/components/Message/MarkdownContent/MarkdownImage/types.ts +8 -0
- package/src/components/Message/MarkdownContent/styles.ts +61 -0
- package/src/components/Message/MarkdownContent/types.ts +4 -0
- package/src/components/Message/Message.tsx +137 -0
- package/src/components/Message/constants.ts +2 -0
- package/src/components/Message/index.ts +10 -0
- package/src/components/Message/isNestedAction.ts +22 -0
- package/src/components/Message/styles.ts +42 -0
- package/src/components/Message/types.ts +45 -0
- package/src/components/MessageList/MessageList.tsx +238 -0
- package/src/components/MessageList/constants.ts +1 -0
- package/src/components/MessageList/index.ts +6 -0
- package/src/components/MessageList/styles.ts +7 -0
- package/src/components/MessageList/types.ts +36 -0
- package/src/components/MessageList/webPrependAnchor/constants.ts +6 -0
- package/src/components/MessageList/webPrependAnchor/index.ts +7 -0
- package/src/components/MessageList/webPrependAnchor/types.ts +92 -0
- package/src/components/MessageList/webPrependAnchor/useWebPrependAnchor.ts +27 -0
- package/src/components/MessageList/webPrependAnchor/useWebPrependAnchor.web.ts +293 -0
- package/src/components/Process/Process.tsx +160 -0
- package/src/components/Process/constants.ts +22 -0
- package/src/components/Process/index.ts +9 -0
- package/src/components/Process/styles.ts +77 -0
- package/src/components/Process/types.ts +39 -0
- package/src/components/Sources/Sources.tsx +70 -0
- package/src/components/Sources/constants.ts +1 -0
- package/src/components/Sources/index.ts +2 -0
- package/src/components/Sources/styles.ts +59 -0
- package/src/components/Sources/types.ts +17 -0
- package/src/components/Suggestions/Suggestions.tsx +34 -0
- package/src/components/Suggestions/index.ts +2 -0
- package/src/components/Suggestions/styles.ts +16 -0
- package/src/components/Suggestions/types.ts +19 -0
- package/src/index.tsx +61 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Image, View } from 'react-native';
|
|
3
|
+
import { Icon, Thumbnail } from '@unif/react-native-design';
|
|
4
|
+
import { styles } from './styles';
|
|
5
|
+
import type { ImageRatio, MarkdownImageProps } from './types';
|
|
6
|
+
|
|
7
|
+
export function MarkdownImage({ uri, label }: MarkdownImageProps) {
|
|
8
|
+
const [width, setWidth] = useState(1);
|
|
9
|
+
const [ratio, setRatio] = useState<ImageRatio | undefined>(undefined);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
let active = true;
|
|
12
|
+
// 只取资源几何;加载与失败占位仍由 Design Thumbnail 持有。
|
|
13
|
+
Image.getSize(
|
|
14
|
+
uri,
|
|
15
|
+
(imageWidth, imageHeight) => {
|
|
16
|
+
if (
|
|
17
|
+
active &&
|
|
18
|
+
Number.isFinite(imageWidth) &&
|
|
19
|
+
Number.isFinite(imageHeight) &&
|
|
20
|
+
imageWidth > 0 &&
|
|
21
|
+
imageHeight > 0
|
|
22
|
+
) {
|
|
23
|
+
setRatio({ uri, value: imageWidth / imageHeight });
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
() => {}
|
|
27
|
+
);
|
|
28
|
+
return () => {
|
|
29
|
+
active = false;
|
|
30
|
+
};
|
|
31
|
+
}, [uri]);
|
|
32
|
+
return (
|
|
33
|
+
<View
|
|
34
|
+
style={styles.root}
|
|
35
|
+
onLayout={({ nativeEvent: { layout } }) =>
|
|
36
|
+
setWidth(Math.max(1, layout.width))
|
|
37
|
+
}
|
|
38
|
+
>
|
|
39
|
+
<Thumbnail
|
|
40
|
+
source={{ uri }}
|
|
41
|
+
size={{
|
|
42
|
+
width,
|
|
43
|
+
height: width / (ratio?.uri === uri ? ratio.value : 1),
|
|
44
|
+
borderRadius: 0,
|
|
45
|
+
}}
|
|
46
|
+
resizeMode="contain"
|
|
47
|
+
fallback={<Icon name="image" />}
|
|
48
|
+
accessibilityLabel={label || '图片'}
|
|
49
|
+
/>
|
|
50
|
+
</View>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { type, space, fontMono } from '@unif/react-native-design';
|
|
3
|
+
import type { ColorTokens } from '@unif/react-native-design';
|
|
4
|
+
|
|
5
|
+
export const createStyles = (colors: ColorTokens) => {
|
|
6
|
+
const body = {
|
|
7
|
+
fontSize: type.body,
|
|
8
|
+
lineHeight: type.body * 1.5,
|
|
9
|
+
color: colors.foreground,
|
|
10
|
+
};
|
|
11
|
+
return StyleSheet.create({
|
|
12
|
+
text: body,
|
|
13
|
+
em: { ...body, fontStyle: 'italic' },
|
|
14
|
+
strong: { ...body, fontWeight: 'bold' },
|
|
15
|
+
strikethrough: { ...body, textDecorationLine: 'line-through' },
|
|
16
|
+
link: { ...body, color: colors.primary },
|
|
17
|
+
li: body,
|
|
18
|
+
codespan: {
|
|
19
|
+
...body,
|
|
20
|
+
fontFamily: fontMono,
|
|
21
|
+
backgroundColor: colors.surfaceContainer,
|
|
22
|
+
},
|
|
23
|
+
h1: {
|
|
24
|
+
fontSize: type.h1,
|
|
25
|
+
lineHeight: type.h1 * 1.4,
|
|
26
|
+
color: colors.foreground,
|
|
27
|
+
borderBottomColor: colors.outline,
|
|
28
|
+
},
|
|
29
|
+
h2: {
|
|
30
|
+
fontSize: type.h2,
|
|
31
|
+
lineHeight: type.h2 * 1.4,
|
|
32
|
+
color: colors.foreground,
|
|
33
|
+
borderBottomColor: colors.outline,
|
|
34
|
+
},
|
|
35
|
+
h3: {
|
|
36
|
+
fontSize: type.h3,
|
|
37
|
+
lineHeight: type.h3 * 1.4,
|
|
38
|
+
color: colors.foreground,
|
|
39
|
+
},
|
|
40
|
+
h4: {
|
|
41
|
+
fontSize: type.body,
|
|
42
|
+
lineHeight: type.body * 1.4,
|
|
43
|
+
color: colors.foreground,
|
|
44
|
+
},
|
|
45
|
+
h5: {
|
|
46
|
+
fontSize: type.sm,
|
|
47
|
+
lineHeight: type.sm * 1.4,
|
|
48
|
+
color: colors.foreground,
|
|
49
|
+
},
|
|
50
|
+
h6: {
|
|
51
|
+
fontSize: type.xs,
|
|
52
|
+
lineHeight: type.xs * 1.4,
|
|
53
|
+
color: colors.foreground,
|
|
54
|
+
},
|
|
55
|
+
paragraph: { paddingVertical: space[1] },
|
|
56
|
+
code: { padding: space[2], backgroundColor: colors.surfaceContainer },
|
|
57
|
+
blockquote: { borderLeftColor: colors.outline },
|
|
58
|
+
hr: { borderBottomColor: colors.outline },
|
|
59
|
+
table: { borderColor: colors.outline },
|
|
60
|
+
});
|
|
61
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Pressable, Text, View } from 'react-native';
|
|
2
|
+
import { Button, Spinner, useThemedStyles } from '@unif/react-native-design';
|
|
3
|
+
import { MarkdownContent } from './MarkdownContent/MarkdownContent';
|
|
4
|
+
import { createStyles } from './styles';
|
|
5
|
+
import { isNestedAction } from './isNestedAction';
|
|
6
|
+
import type { MessageProps } from './types';
|
|
7
|
+
|
|
8
|
+
export function Message(props: MessageProps) {
|
|
9
|
+
const {
|
|
10
|
+
placement = 'start',
|
|
11
|
+
avatar,
|
|
12
|
+
name,
|
|
13
|
+
surface = 'bubble',
|
|
14
|
+
fullWidth = false,
|
|
15
|
+
status = 'idle',
|
|
16
|
+
statusText,
|
|
17
|
+
header,
|
|
18
|
+
footer,
|
|
19
|
+
actions = [],
|
|
20
|
+
onPress,
|
|
21
|
+
onLongPress,
|
|
22
|
+
style,
|
|
23
|
+
testID,
|
|
24
|
+
} = props;
|
|
25
|
+
const styles = useThemedStyles(createStyles);
|
|
26
|
+
const hasContent =
|
|
27
|
+
Boolean(props.text?.length) ||
|
|
28
|
+
(props.children !== undefined &&
|
|
29
|
+
props.children !== null &&
|
|
30
|
+
props.children !== false) ||
|
|
31
|
+
(header !== undefined && header !== null && header !== false) ||
|
|
32
|
+
(footer !== undefined && footer !== null && footer !== false);
|
|
33
|
+
const waiting =
|
|
34
|
+
(status === 'pending' || status === 'streaming') && !hasContent;
|
|
35
|
+
const contentStyle = [
|
|
36
|
+
styles.content,
|
|
37
|
+
fullWidth && styles.fullWidth,
|
|
38
|
+
surface === 'bubble' && [
|
|
39
|
+
styles.bubble,
|
|
40
|
+
placement === 'end' && styles.outgoing,
|
|
41
|
+
],
|
|
42
|
+
surface === 'outlined' && styles.outlined,
|
|
43
|
+
status === 'failed' && styles.failed,
|
|
44
|
+
];
|
|
45
|
+
const content = (
|
|
46
|
+
<>
|
|
47
|
+
{header}
|
|
48
|
+
{props.text !== undefined ? (
|
|
49
|
+
props.format === 'markdown' ? (
|
|
50
|
+
<MarkdownContent text={props.text} onLinkPress={props.onLinkPress} />
|
|
51
|
+
) : (
|
|
52
|
+
<Text
|
|
53
|
+
selectable
|
|
54
|
+
style={styles.text}
|
|
55
|
+
numberOfLines={props.numberOfLines}
|
|
56
|
+
>
|
|
57
|
+
{props.text}
|
|
58
|
+
</Text>
|
|
59
|
+
)
|
|
60
|
+
) : (
|
|
61
|
+
props.children
|
|
62
|
+
)}
|
|
63
|
+
{waiting ? (
|
|
64
|
+
<View
|
|
65
|
+
accessible
|
|
66
|
+
accessibilityLabel="正在等待回复"
|
|
67
|
+
accessibilityState={{ busy: true }}
|
|
68
|
+
>
|
|
69
|
+
<Spinner />
|
|
70
|
+
</View>
|
|
71
|
+
) : null}
|
|
72
|
+
{statusText ? (
|
|
73
|
+
<Text style={[styles.status, status === 'failed' && styles.errorText]}>
|
|
74
|
+
{statusText}
|
|
75
|
+
</Text>
|
|
76
|
+
) : null}
|
|
77
|
+
{footer}
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
return (
|
|
81
|
+
<View
|
|
82
|
+
style={[styles.root, placement === 'end' && styles.end, style]}
|
|
83
|
+
testID={testID}
|
|
84
|
+
>
|
|
85
|
+
{avatar}
|
|
86
|
+
<View
|
|
87
|
+
style={[
|
|
88
|
+
styles.column,
|
|
89
|
+
placement === 'end' && styles.columnEnd,
|
|
90
|
+
fullWidth && styles.fullWidth,
|
|
91
|
+
]}
|
|
92
|
+
>
|
|
93
|
+
{name ? <Text style={styles.name}>{name}</Text> : null}
|
|
94
|
+
{onPress || onLongPress ? (
|
|
95
|
+
<Pressable
|
|
96
|
+
style={contentStyle}
|
|
97
|
+
onPress={
|
|
98
|
+
onPress
|
|
99
|
+
? (event) => {
|
|
100
|
+
if (!isNestedAction(event)) onPress();
|
|
101
|
+
}
|
|
102
|
+
: undefined
|
|
103
|
+
}
|
|
104
|
+
onLongPress={
|
|
105
|
+
onLongPress
|
|
106
|
+
? (event) => {
|
|
107
|
+
if (!isNestedAction(event)) onLongPress();
|
|
108
|
+
}
|
|
109
|
+
: undefined
|
|
110
|
+
}
|
|
111
|
+
accessible={false}
|
|
112
|
+
>
|
|
113
|
+
{content}
|
|
114
|
+
</Pressable>
|
|
115
|
+
) : (
|
|
116
|
+
<View style={contentStyle}>{content}</View>
|
|
117
|
+
)}
|
|
118
|
+
{actions.length ? (
|
|
119
|
+
<View style={styles.actions}>
|
|
120
|
+
{actions.map((action) => (
|
|
121
|
+
<Button
|
|
122
|
+
key={action.id}
|
|
123
|
+
label={action.label}
|
|
124
|
+
leftIcon={action.icon}
|
|
125
|
+
disabled={action.disabled}
|
|
126
|
+
loading={action.loading}
|
|
127
|
+
accessibilityHint={action.accessibilityHint}
|
|
128
|
+
variant="text"
|
|
129
|
+
onPress={action.onPress}
|
|
130
|
+
/>
|
|
131
|
+
))}
|
|
132
|
+
</View>
|
|
133
|
+
) : null}
|
|
134
|
+
</View>
|
|
135
|
+
</View>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { GestureResponderEvent } from 'react-native';
|
|
2
|
+
import { INTERACTIVE_CONTENT_SELECTOR } from './constants';
|
|
3
|
+
|
|
4
|
+
export function isNestedAction(event: GestureResponderEvent): boolean {
|
|
5
|
+
const { target, currentTarget } = event;
|
|
6
|
+
// 原生由 responder 交付实际目标;Web 的 RNGH 按钮仍可能冒泡到 RN Pressable。
|
|
7
|
+
if (
|
|
8
|
+
typeof target !== 'object' ||
|
|
9
|
+
target === null ||
|
|
10
|
+
!('closest' in target) ||
|
|
11
|
+
typeof target.closest !== 'function' ||
|
|
12
|
+
typeof currentTarget !== 'object' ||
|
|
13
|
+
currentTarget === null ||
|
|
14
|
+
!('contains' in currentTarget) ||
|
|
15
|
+
typeof currentTarget.contains !== 'function'
|
|
16
|
+
)
|
|
17
|
+
return false;
|
|
18
|
+
const action = target.closest(INTERACTIVE_CONTENT_SELECTOR);
|
|
19
|
+
return Boolean(
|
|
20
|
+
action && action !== currentTarget && currentTarget.contains(action)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { radius, space, type } from '@unif/react-native-design';
|
|
3
|
+
import type { ColorTokens } from '@unif/react-native-design';
|
|
4
|
+
|
|
5
|
+
export const createStyles = (colors: ColorTokens) =>
|
|
6
|
+
StyleSheet.create({
|
|
7
|
+
root: {
|
|
8
|
+
flexDirection: 'row',
|
|
9
|
+
alignItems: 'flex-start',
|
|
10
|
+
gap: space[2],
|
|
11
|
+
minWidth: 0,
|
|
12
|
+
paddingVertical: space[2],
|
|
13
|
+
},
|
|
14
|
+
end: { flexDirection: 'row-reverse' },
|
|
15
|
+
column: {
|
|
16
|
+
flexShrink: 1,
|
|
17
|
+
maxWidth: '100%',
|
|
18
|
+
gap: space[1],
|
|
19
|
+
alignItems: 'flex-start',
|
|
20
|
+
},
|
|
21
|
+
columnEnd: { alignItems: 'flex-end' },
|
|
22
|
+
fullWidth: { flex: 1, alignSelf: 'stretch' },
|
|
23
|
+
content: { minWidth: 0, maxWidth: '100%', gap: space[2] },
|
|
24
|
+
bubble: {
|
|
25
|
+
padding: space[3],
|
|
26
|
+
borderRadius: radius.lg,
|
|
27
|
+
backgroundColor: colors.surface,
|
|
28
|
+
},
|
|
29
|
+
outgoing: { backgroundColor: colors.primaryContainer },
|
|
30
|
+
outlined: {
|
|
31
|
+
padding: space[3],
|
|
32
|
+
borderRadius: radius.lg,
|
|
33
|
+
borderWidth: 1,
|
|
34
|
+
borderColor: colors.outline,
|
|
35
|
+
},
|
|
36
|
+
failed: { borderWidth: 1, borderColor: colors.error },
|
|
37
|
+
text: { fontSize: type.body, color: colors.foreground },
|
|
38
|
+
name: { fontSize: type.sm, color: colors.foregroundMuted },
|
|
39
|
+
status: { fontSize: type.sm, color: colors.foregroundMuted },
|
|
40
|
+
errorText: { color: colors.error },
|
|
41
|
+
actions: { flexDirection: 'row', flexWrap: 'wrap', gap: space[2] },
|
|
42
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import type { ChatAction } from '../../actions';
|
|
4
|
+
|
|
5
|
+
export type MessagePlacement = 'start' | 'end';
|
|
6
|
+
export type MessageStatus = 'idle' | 'pending' | 'streaming' | 'failed';
|
|
7
|
+
export interface MessageBaseProps {
|
|
8
|
+
placement?: MessagePlacement;
|
|
9
|
+
avatar?: ReactNode;
|
|
10
|
+
name?: string;
|
|
11
|
+
surface?: 'bubble' | 'outlined' | 'plain';
|
|
12
|
+
fullWidth?: boolean;
|
|
13
|
+
status?: MessageStatus;
|
|
14
|
+
statusText?: string;
|
|
15
|
+
header?: ReactNode;
|
|
16
|
+
footer?: ReactNode;
|
|
17
|
+
actions?: readonly ChatAction[];
|
|
18
|
+
onPress?(): void;
|
|
19
|
+
onLongPress?(): void;
|
|
20
|
+
style?: StyleProp<ViewStyle>;
|
|
21
|
+
testID?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface MessagePlainContent {
|
|
24
|
+
text: string;
|
|
25
|
+
format?: 'text';
|
|
26
|
+
numberOfLines?: number;
|
|
27
|
+
children?: never;
|
|
28
|
+
onLinkPress?: never;
|
|
29
|
+
}
|
|
30
|
+
export interface MessageMarkdownContent {
|
|
31
|
+
text: string;
|
|
32
|
+
format: 'markdown';
|
|
33
|
+
onLinkPress?(url: string): void;
|
|
34
|
+
numberOfLines?: never;
|
|
35
|
+
children?: never;
|
|
36
|
+
}
|
|
37
|
+
export interface MessageCustomContent {
|
|
38
|
+
children?: ReactNode;
|
|
39
|
+
text?: never;
|
|
40
|
+
format?: never;
|
|
41
|
+
numberOfLines?: never;
|
|
42
|
+
onLinkPress?: never;
|
|
43
|
+
}
|
|
44
|
+
export type MessageProps = MessageBaseProps &
|
|
45
|
+
(MessagePlainContent | MessageMarkdownContent | MessageCustomContent);
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { useImperativeHandle, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { RefAttributes } from 'react';
|
|
3
|
+
import { FlatList, View } from 'react-native';
|
|
4
|
+
import type { NativeScrollEvent, NativeSyntheticEvent } from 'react-native';
|
|
5
|
+
import { Button } from '@unif/react-native-design';
|
|
6
|
+
import { DEFAULT_END_THRESHOLD } from './constants';
|
|
7
|
+
import { styles } from './styles';
|
|
8
|
+
import { useWebPrependAnchor } from './webPrependAnchor';
|
|
9
|
+
import type {
|
|
10
|
+
ListMeasurements,
|
|
11
|
+
MessageListHandle,
|
|
12
|
+
MessageListProps,
|
|
13
|
+
MessageListScrollOptions,
|
|
14
|
+
} from './types';
|
|
15
|
+
|
|
16
|
+
export function MessageList<T>({
|
|
17
|
+
items,
|
|
18
|
+
keyExtractor,
|
|
19
|
+
renderItem,
|
|
20
|
+
extraData,
|
|
21
|
+
header,
|
|
22
|
+
footer,
|
|
23
|
+
empty,
|
|
24
|
+
renderSeparator,
|
|
25
|
+
initialPosition = 'end',
|
|
26
|
+
followOutput = 'whenAtEnd',
|
|
27
|
+
endThreshold = DEFAULT_END_THRESHOLD,
|
|
28
|
+
showScrollToEnd = true,
|
|
29
|
+
onAtEndChange,
|
|
30
|
+
hasEarlier = false,
|
|
31
|
+
loadingEarlier = false,
|
|
32
|
+
onRequestEarlier,
|
|
33
|
+
keyboardDismissMode = 'on-drag',
|
|
34
|
+
style,
|
|
35
|
+
testID,
|
|
36
|
+
ref,
|
|
37
|
+
}: MessageListProps<T> & RefAttributes<MessageListHandle>) {
|
|
38
|
+
const listRef = useRef<FlatList<T>>(null);
|
|
39
|
+
const measurements = useRef<ListMeasurements>({
|
|
40
|
+
viewport: 0,
|
|
41
|
+
content: 0,
|
|
42
|
+
offset: 0,
|
|
43
|
+
hasContentSize: false,
|
|
44
|
+
});
|
|
45
|
+
const initial = useRef(initialPosition);
|
|
46
|
+
const initialized = useRef(false);
|
|
47
|
+
const previousKeys = useRef<readonly string[]>([]);
|
|
48
|
+
const prependPending = useRef(false);
|
|
49
|
+
const pendingScroll = useRef<MessageListScrollOptions | undefined>(undefined);
|
|
50
|
+
const userScrolling = useRef(false);
|
|
51
|
+
const atEndRef = useRef<boolean | undefined>(undefined);
|
|
52
|
+
const [atEnd, setAtEnd] = useState(true);
|
|
53
|
+
const threshold = Number.isFinite(endThreshold)
|
|
54
|
+
? Math.max(0, endThreshold)
|
|
55
|
+
: DEFAULT_END_THRESHOLD;
|
|
56
|
+
const keys = items.map(keyExtractor);
|
|
57
|
+
const { getRowNativeID, preservingPrependRef, cancelPrependPreservation } =
|
|
58
|
+
useWebPrependAnchor({ listRef, itemsIdentity: items, keys });
|
|
59
|
+
|
|
60
|
+
useLayoutEffect(() => {
|
|
61
|
+
const previous = previousKeys.current;
|
|
62
|
+
const added = keys.length - previous.length;
|
|
63
|
+
const onlyPrepended =
|
|
64
|
+
previous.length > 0 &&
|
|
65
|
+
added > 0 &&
|
|
66
|
+
previous.every((key, index) => keys[index + added] === key);
|
|
67
|
+
const changed =
|
|
68
|
+
keys.length !== previous.length ||
|
|
69
|
+
keys.some((key, index) => key !== previous[index]);
|
|
70
|
+
if (changed) prependPending.current = onlyPrepended;
|
|
71
|
+
previousKeys.current = keys;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
function ready() {
|
|
75
|
+
const current = measurements.current;
|
|
76
|
+
return current.viewport > 0 && current.hasContentSize;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function publishPosition() {
|
|
80
|
+
if (!ready()) return;
|
|
81
|
+
const { viewport, content, offset } = measurements.current;
|
|
82
|
+
const next = content - viewport - Math.max(0, offset) <= threshold;
|
|
83
|
+
if (next !== atEndRef.current) {
|
|
84
|
+
atEndRef.current = next;
|
|
85
|
+
setAtEnd(next);
|
|
86
|
+
onAtEndChange?.(next);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function scrollToEnd(options: MessageListScrollOptions = {}) {
|
|
91
|
+
cancelPrependPreservation();
|
|
92
|
+
const request = { animated: options.animated ?? true };
|
|
93
|
+
if (!ready()) {
|
|
94
|
+
pendingScroll.current = request;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
pendingScroll.current = undefined;
|
|
98
|
+
listRef.current?.scrollToOffset({
|
|
99
|
+
offset: Math.max(
|
|
100
|
+
0,
|
|
101
|
+
measurements.current.content - measurements.current.viewport
|
|
102
|
+
),
|
|
103
|
+
animated: request.animated,
|
|
104
|
+
});
|
|
105
|
+
if (measurements.current.content <= measurements.current.viewport)
|
|
106
|
+
publishPosition();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
useImperativeHandle(ref, () => ({ scrollToEnd }));
|
|
110
|
+
|
|
111
|
+
function reconcileLayout(contentChanged: boolean) {
|
|
112
|
+
if (!ready()) return;
|
|
113
|
+
const request = pendingScroll.current;
|
|
114
|
+
if (items.length > 0 && !initialized.current) {
|
|
115
|
+
initialized.current = true;
|
|
116
|
+
if (request || initial.current === 'end') {
|
|
117
|
+
scrollToEnd(request ?? { animated: false });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
publishPosition();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (request) {
|
|
124
|
+
scrollToEnd(request);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const prepended = prependPending.current;
|
|
128
|
+
if (contentChanged) prependPending.current = false;
|
|
129
|
+
const shouldFollow =
|
|
130
|
+
initialized.current &&
|
|
131
|
+
followOutput === 'whenAtEnd' &&
|
|
132
|
+
!userScrolling.current &&
|
|
133
|
+
!prepended &&
|
|
134
|
+
!preservingPrependRef.current &&
|
|
135
|
+
atEndRef.current;
|
|
136
|
+
if (shouldFollow) scrollToEnd({ animated: false });
|
|
137
|
+
else publishPosition();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function onScroll(event: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
141
|
+
const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;
|
|
142
|
+
const movedUp = contentOffset.y < measurements.current.offset;
|
|
143
|
+
const resizingAtEnd =
|
|
144
|
+
atEndRef.current &&
|
|
145
|
+
!movedUp &&
|
|
146
|
+
!userScrolling.current &&
|
|
147
|
+
followOutput === 'whenAtEnd' &&
|
|
148
|
+
(measurements.current.content !== contentSize.height ||
|
|
149
|
+
measurements.current.viewport !== layoutMeasurement.height);
|
|
150
|
+
measurements.current = {
|
|
151
|
+
offset: contentOffset.y,
|
|
152
|
+
content: contentSize.height,
|
|
153
|
+
viewport: layoutMeasurement.height,
|
|
154
|
+
hasContentSize: true,
|
|
155
|
+
};
|
|
156
|
+
if (!resizingAtEnd) publishPosition();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const history = hasEarlier && onRequestEarlier;
|
|
160
|
+
const hasHeader = Boolean(header || history);
|
|
161
|
+
return (
|
|
162
|
+
<View style={[styles.root, style]} testID={testID}>
|
|
163
|
+
<FlatList
|
|
164
|
+
ref={listRef}
|
|
165
|
+
testID={testID ? `${testID}-list` : undefined}
|
|
166
|
+
style={styles.list}
|
|
167
|
+
data={items}
|
|
168
|
+
keyExtractor={keyExtractor}
|
|
169
|
+
extraData={extraData}
|
|
170
|
+
renderItem={({ item, index }) => (
|
|
171
|
+
<View nativeID={getRowNativeID(keyExtractor(item))}>
|
|
172
|
+
{index > 0 && renderSeparator
|
|
173
|
+
? renderSeparator(items[index - 1]!, item)
|
|
174
|
+
: null}
|
|
175
|
+
{renderItem(item, index)}
|
|
176
|
+
</View>
|
|
177
|
+
)}
|
|
178
|
+
ListHeaderComponent={
|
|
179
|
+
hasHeader ? (
|
|
180
|
+
<View>
|
|
181
|
+
{header}
|
|
182
|
+
{history ? (
|
|
183
|
+
<Button
|
|
184
|
+
label={loadingEarlier ? '正在加载…' : '查看更早消息'}
|
|
185
|
+
variant="text"
|
|
186
|
+
loading={loadingEarlier}
|
|
187
|
+
onPress={onRequestEarlier}
|
|
188
|
+
/>
|
|
189
|
+
) : null}
|
|
190
|
+
</View>
|
|
191
|
+
) : undefined
|
|
192
|
+
}
|
|
193
|
+
ListFooterComponent={footer ? <View>{footer}</View> : undefined}
|
|
194
|
+
ListEmptyComponent={empty ? <View>{empty}</View> : undefined}
|
|
195
|
+
maintainVisibleContentPosition={{ minIndexForVisible: 0 }}
|
|
196
|
+
keyboardDismissMode={keyboardDismissMode}
|
|
197
|
+
keyboardShouldPersistTaps="handled"
|
|
198
|
+
scrollEventThrottle={16}
|
|
199
|
+
onLayout={({ nativeEvent: { layout } }) => {
|
|
200
|
+
measurements.current.viewport = layout.height;
|
|
201
|
+
reconcileLayout(false);
|
|
202
|
+
}}
|
|
203
|
+
onContentSizeChange={(_width, height) => {
|
|
204
|
+
measurements.current.content = height;
|
|
205
|
+
measurements.current.hasContentSize = true;
|
|
206
|
+
reconcileLayout(true);
|
|
207
|
+
}}
|
|
208
|
+
onScroll={onScroll}
|
|
209
|
+
onScrollBeginDrag={() => {
|
|
210
|
+
userScrolling.current = true;
|
|
211
|
+
}}
|
|
212
|
+
onMomentumScrollBegin={() => {
|
|
213
|
+
userScrolling.current = true;
|
|
214
|
+
}}
|
|
215
|
+
onScrollEndDrag={(event) => {
|
|
216
|
+
onScroll(event);
|
|
217
|
+
if (!event.nativeEvent.velocity?.y) {
|
|
218
|
+
userScrolling.current = false;
|
|
219
|
+
publishPosition();
|
|
220
|
+
}
|
|
221
|
+
}}
|
|
222
|
+
onMomentumScrollEnd={(event) => {
|
|
223
|
+
onScroll(event);
|
|
224
|
+
userScrolling.current = false;
|
|
225
|
+
publishPosition();
|
|
226
|
+
}}
|
|
227
|
+
/>
|
|
228
|
+
{showScrollToEnd && items.length > 0 && !atEnd ? (
|
|
229
|
+
<Button
|
|
230
|
+
label="回到最新消息"
|
|
231
|
+
variant="secondary"
|
|
232
|
+
style={styles.returnToEnd}
|
|
233
|
+
onPress={() => scrollToEnd()}
|
|
234
|
+
/>
|
|
235
|
+
) : null}
|
|
236
|
+
</View>
|
|
237
|
+
);
|
|
238
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_END_THRESHOLD = 24;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { space } from '@unif/react-native-design';
|
|
3
|
+
export const styles = StyleSheet.create({
|
|
4
|
+
root: { flex: 1, minHeight: 0, minWidth: 0 },
|
|
5
|
+
list: { flex: 1 },
|
|
6
|
+
returnToEnd: { position: 'absolute', bottom: space[3], alignSelf: 'center' },
|
|
7
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface MessageListScrollOptions {
|
|
5
|
+
animated?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface MessageListHandle {
|
|
8
|
+
scrollToEnd(options?: MessageListScrollOptions): void;
|
|
9
|
+
}
|
|
10
|
+
export interface MessageListProps<T> {
|
|
11
|
+
items: readonly T[];
|
|
12
|
+
keyExtractor(item: T): string;
|
|
13
|
+
renderItem(item: T, index: number): ReactNode;
|
|
14
|
+
extraData?: unknown;
|
|
15
|
+
header?: ReactNode;
|
|
16
|
+
footer?: ReactNode;
|
|
17
|
+
empty?: ReactNode;
|
|
18
|
+
renderSeparator?(previous: T, next: T): ReactNode;
|
|
19
|
+
initialPosition?: 'start' | 'end';
|
|
20
|
+
followOutput?: 'whenAtEnd' | 'never';
|
|
21
|
+
endThreshold?: number;
|
|
22
|
+
showScrollToEnd?: boolean;
|
|
23
|
+
onAtEndChange?(atEnd: boolean): void;
|
|
24
|
+
hasEarlier?: boolean;
|
|
25
|
+
loadingEarlier?: boolean;
|
|
26
|
+
onRequestEarlier?(): void;
|
|
27
|
+
keyboardDismissMode?: 'none' | 'on-drag';
|
|
28
|
+
style?: StyleProp<ViewStyle>;
|
|
29
|
+
testID?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ListMeasurements {
|
|
32
|
+
viewport: number;
|
|
33
|
+
content: number;
|
|
34
|
+
offset: number;
|
|
35
|
+
hasContentSize: boolean;
|
|
36
|
+
}
|