UNPKG

react-native-pure-chat-view

Version:
423 lines (363 loc) 11 kB
import React, { PureComponent, } from 'react' import ReactNative, { UIManager, requireNativeComponent } from 'react-native' import PropTypes from 'prop-types' class ChatView extends PureComponent { static propTypes = { currentUserId: PropTypes.string.isRequired, backgroundColor: PropTypes.string.isRequired, leftUserNameVisible: PropTypes.bool.isRequired, rightUserNameVisible: PropTypes.bool.isRequired, userAvatarWidth: PropTypes.number.isRequired, userAvatarHeight: PropTypes.number.isRequired, userAvatarBorderRadius: PropTypes.number.isRequired, onReady: PropTypes.func, onListClick: PropTypes.func, onUserNameClick: PropTypes.func, onUserAvatarClick: PropTypes.func, onContentClick: PropTypes.func, onFailureClick: PropTypes.func, onLinkClick: PropTypes.func, onCopyClick: PropTypes.func, onShareClick: PropTypes.func, onRecallClick: PropTypes.func, onDeleteClick: PropTypes.func, onLoadMore: PropTypes.func, onRecordAudioDurationLessThanMinDuration: PropTypes.func, onRecordAudioExternalStorageNotWritable: PropTypes.func, onRecordAudioPermissionsNotGranted: PropTypes.func, onRecordAudioPermissionsGranted: PropTypes.func, onRecordAudioPermissionsDenied: PropTypes.func, onSendAudio: PropTypes.func, onSendText: PropTypes.func, onTextChange: PropTypes.func, onPhotoFeatureClick: PropTypes.func, onCameraFeatureClick: PropTypes.func, onFileFeatureClick: PropTypes.func, onUserFeatureClick: PropTypes.func, onMovieFeatureClick: PropTypes.func, onPhoneFeatureClick: PropTypes.func, onLocationFeatureClick: PropTypes.func, onFavorFeatureClick: PropTypes.func, onLift: PropTypes.func, onFall: PropTypes.func, } appendMessage(message, scrollToBottom) { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.appendMessage, [message, scrollToBottom ? true : false], ) } appendMessages(messages, scrollToBottom) { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.appendMessages, [messages, scrollToBottom ? true : false], ) } prependMessage(message, scrollToBottom) { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.prependMessage, [message, scrollToBottom ? true : false], ) } prependMessages(messages, scrollToBottom) { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.prependMessages, [messages, scrollToBottom ? true : false], ) } removeMessage(messageId, scrollToBottom) { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.removeMessage, [messageId, scrollToBottom ? true : false], ) } removeAllMessages() { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.removeAllMessages, null, ) } updateMessage(messageId, message, scrollToBottom) { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.updateMessage, [messageId, message, scrollToBottom ? true : false], ) } setAllMessages(messages, scrollToBottom) { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.setAllMessages, [messages, scrollToBottom ? true : false], ) } stopAudio() { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.stopAudio, null, ) } loadMoreComplete(hasMoreMessage) { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.loadMoreComplete, [hasMoreMessage ? true : false], ) } scrollToBottom(animated) { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.scrollToBottom, [animated ? true : false], ) } setText(text) { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.setText, [text] ) } resetInput() { UIManager.dispatchViewManagerCommand( this.getNativeNode(), UIManager.RNTChatView.Commands.resetInput, null ) } handleReady = () => { let { onReady } = this.props if (onReady) { onReady() } } handleListClick = () => { let { onListClick } = this.props if (onListClick) { onListClick() } } handleUserNameClick = (event) => { let { onUserNameClick } = this.props if (onUserNameClick) { onUserNameClick(event.nativeEvent) } } handleUserAvatarClick = (event) => { let { onUserAvatarClick } = this.props if (onUserAvatarClick) { onUserAvatarClick(event.nativeEvent) } } handleContentClick = (event) => { let { onContentClick } = this.props if (onContentClick) { onContentClick(event.nativeEvent) } } handleFailureClick = (event) => { let { onFailureClick } = this.props if (onFailureClick) { onFailureClick(event.nativeEvent) } } handleLinkClick = (event) => { let { onLinkClick } = this.props if (onLinkClick) { onLinkClick(event.nativeEvent) } } handleCopyClick = (event) => { let { onCopyClick } = this.props if (onCopyClick) { onCopyClick(event.nativeEvent) } } handleShareClick = (event) => { let { onShareClick } = this.props if (onShareClick) { onShareClick(event.nativeEvent) } } handleRecallClick = (event) => { let { onRecallClick } = this.props if (onRecallClick) { onRecallClick(event.nativeEvent) } } handleDeleteClick = (event) => { let { onDeleteClick } = this.props if (onDeleteClick) { onDeleteClick(event.nativeEvent) } } handleLoadMore = () => { let { onLoadMore } = this.props if (onLoadMore) { onLoadMore() } } handleRecordAudioDurationLessThanMinDuration = () => { let { onRecordAudioDurationLessThanMinDuration } = this.props if (onRecordAudioDurationLessThanMinDuration) { onRecordAudioDurationLessThanMinDuration() } } handleRecordAudioExternalStorageNotWritable = () => { let { onRecordAudioExternalStorageNotWritable } = this.props if (onRecordAudioExternalStorageNotWritable) { onRecordAudioExternalStorageNotWritable() } } handleRecordAudioPermissionsNotGranted = () => { let { onRecordAudioPermissionsNotGranted } = this.props if (onRecordAudioPermissionsNotGranted) { onRecordAudioPermissionsNotGranted() } } handleRecordAudioPermissionsGranted = () => { let { onRecordAudioPermissionsGranted } = this.props if (onRecordAudioPermissionsGranted) { onRecordAudioPermissionsGranted() } } handleRecordAudioPermissionsDenied = () => { let { onRecordAudioPermissionsDenied } = this.props if (onRecordAudioPermissionsDenied) { onRecordAudioPermissionsDenied() } } handleSendAudio = (event) => { let { onSendAudio } = this.props if (onSendAudio) { onSendAudio(event.nativeEvent) } } handleSendText = (event) => { let { onSendText } = this.props if (onSendText) { onSendText(event.nativeEvent) } } handleTextChange = (event) => { let { onTextChange } = this.props if (onTextChange) { onTextChange(event.nativeEvent) } } handlePhotoFeatureClick = () => { let { onPhotoFeatureClick } = this.props if (onPhotoFeatureClick) { onPhotoFeatureClick() } } handleCameraFeatureClick = () => { let { onCameraFeatureClick } = this.props if (onCameraFeatureClick) { onCameraFeatureClick() } } handleFileFeatureClick = () => { let { onFileFeatureClick } = this.props if (onFileFeatureClick) { onFileFeatureClick() } } handleUserFeatureClick = () => { let { onUserFeatureClick } = this.props if (onUserFeatureClick) { onUserFeatureClick() } } handleMovieFeatureClick = () => { let { onMovieFeatureClick } = this.props if (onMovieFeatureClick) { onMovieFeatureClick() } } handlePhoneFeatureClick = () => { let { onPhoneFeatureClick } = this.props if (onPhoneFeatureClick) { onPhoneFeatureClick() } } handleLocationFeatureClick = () => { let { onLocationFeatureClick } = this.props if (onLocationFeatureClick) { onLocationFeatureClick() } } handleFavorFeatureClick = () => { let { onFavorFeatureClick } = this.props if (onFavorFeatureClick) { onFavorFeatureClick() } } handleLift = () => { let { onLift } = this.props if (onLift) { onLift() } } handleFall = () => { let { onFall } = this.props if (onFall) { onFall() } } getNativeNode() { return ReactNative.findNodeHandle(this.refs.chatView); } render() { return ( <RNTChatView {...this.props} ref="chatView" onReady={this.handleReady} onListClick={this.handleListClick} onUserNameClick={this.handleUserNameClick} onUserAvatarClick={this.handleUserAvatarClick} onContentClick={this.handleContentClick} onFailureClick={this.handleFailureClick} onLinkClick={this.handleLinkClick} onCopyClick={this.handleCopyClick} onShareClick={this.handleShareClick} onRecallClick={this.handleRecallClick} onDeleteClick={this.handleDeleteClick} onLoadMore={this.handleLoadMore} onRecordAudioDurationLessThanMinDuration={this.handleRecordAudioDurationLessThanMinDuration} onRecordAudioExternalStorageNotWritable={this.handleRecordAudioExternalStorageNotWritable} onRecordAudioPermissionsNotGranted={this.handleRecordAudioPermissionsNotGranted} onRecordAudioPermissionsGranted={this.handleRecordAudioPermissionsGranted} onRecordAudioPermissionsDenied={this.handleRecordAudioPermissionsDenied} onSendAudio={this.handleSendAudio} onSendText={this.handleSendText} onTextChange={this.handleTextChange} onPhotoFeatureClick={this.handlePhotoFeatureClick} onCameraFeatureClick={this.handleCameraFeatureClick} onFileFeatureClick={this.handleFileFeatureClick} onUserFeatureClick={this.handleUserFeatureClick} onMovieFeatureClick={this.handleMovieFeatureClick} onPhoneFeatureClick={this.handlePhoneFeatureClick} onLocationFeatureClick={this.handleLocationFeatureClick} onFavorFeatureClick={this.handleFavorFeatureClick} onLift={this.handleLift} onFall={this.handleFall} /> ) } } const RNTChatView = requireNativeComponent('RNTChatView', ChatView) export default ChatView