为了账号安全,请及时绑定邮箱和手机立即绑定

react-native仿微信app界面聊天室|RN_chatRoom群聊|红包

2019.09.01 23:21 200浏览

react native高仿微信app实例|RN仿微信界面|红包|朋友圈
项目中使用到的弹窗插件:rnPop自定义模态组件|toast提示|dialog对话框

最近一直都在捣鼓react native原生app开发,之前也有使用vue/react/angular等技术开发过聊天室IM,这次是利用RN技术开发的原生app体验。

概述

基于react+react-native+react-navigation+react-redux+react-native-swiper+rnPop等技术开发的仿微信原生App群聊,实现了原生app启动页、AsyncStorage本地存储登录拦截、集成rnPop模态框功能(仿微信popupWindow弹窗菜单)、消息触摸列表、发送消息、表情(动图),图片预览,拍摄图片、发红包、仿微信朋友圈等功能

预览

图片描述

技术实现

  • MVVM框架:react / react-native / react-native-cli
  • 状态管理:react-redux
  • 页面导航:react-navigation
  • rn弹窗组件:rnPop
  • 打包工具:webpack 2.0
  • 轮播组件:react-native-swiper
  • 图片选择:react-native-image-picker
{
  "name": "RN_ChatRoom",
  "aboutMe": "QQ:282310962 、 wx:xy190310",
  
  "scripts": {
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "16.8.6",
    "react-native": "0.60.4"
  },
  "devDependencies": {
    "@babel/core": "^7.5.5",
    "@babel/runtime": "^7.5.5",
    "@react-native-community/async-storage": "^1.6.1",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.8.0",
    "eslint": "^6.1.0",
    "jest": "^24.8.0",
    "metro-react-native-babel-preset": "^0.55.0",
    "react-native-gesture-handler": "^1.3.0",
    "react-native-image-picker": "^1.0.2",
    "react-native-swiper": "^1.5.14",
    "react-navigation": "^3.11.1",
    "react-redux": "^7.1.0",
    "react-test-renderer": "16.8.6",
    "redux": "^4.0.4",
    "redux-thunk": "^2.3.0"
  }
}

基于react-navigation导航器自定义顶部导航条headerBar组件

图片描述

export default class HeaderBar extends Component {
    constructor(props){
        super(props)
        this.state = {
            searchInput: ''
        }
    }

    render() {
        /**
         * 更新
         * @param { navigation | 页面导航 }
         * @param { title | 标题 }
         * @param { center | 标题是否居中 }
         * @param { search | 是否显示搜索 }
         * @param { headerRight | 右侧Icon按钮 }
         */
        let{ navigation, title, bg, center, search, headerRight } = this.props

        return (
            <View style={GStyle.flex_col}>
                <StatusBar backgroundColor={bg ? bg : GStyle.headerBackgroundColor} barStyle='light-content' translucent={true} />
                <View style={[styles.rnim__topBar, GStyle.flex_row, {backgroundColor: bg ? bg : GStyle.headerBackgroundColor}]}>
                    {/* 返回 */}
                    <TouchableOpacity style={[styles.iconBack]} activeOpacity={.5} onPress={this.goBack}><Text style={[GStyle.iconfont, GStyle.c_fff, GStyle.fs_18]}>&#xe63f;</Text></TouchableOpacity>
                    {/* 标题 */}
                    { !search && center ? <View style={GStyle.flex1} /> : null }
                    {
                        search ? 
                        (
                            <View style={[styles.barSearch, GStyle.flex1, GStyle.flex_row]}>
                                <TextInput onChangeText={text=>{this.setState({searchInput: text})}} style={styles.barSearchText} placeholder='搜索' placeholderTextColor='rgba(255,255,255,.6)' />
                            </View>
                        )
                        :
                        (
                            <View style={[styles.barTit, GStyle.flex1, GStyle.flex_row, center ? styles.barTitCenter : null]}>
                                { title ? <Text style={[styles.barCell, {fontSize: 16, paddingLeft: 0}]}>{title}</Text> : null }
                            </View>
                        )
                    }
                    {/* 右侧 */}
                    <View style={[styles.barBtn, GStyle.flex_row]}>
                        { 
                            !headerRight ? null : headerRight.map((item, index) => {
                                return(
                                    <TouchableOpacity style={[styles.iconItem]} activeOpacity={.5} key={index} onPress={()=>item.press ? item.press(this.state.searchInput) : null}>
                                        {
                                            item.type === 'iconfont' ? item.title : (
                                                typeof item.title === 'string' ? 
                                                <Text style={item.style ? item.style : null}>{`${item.title}`}</Text>
                                                :
                                                <Image source={item.title} style={{width: 24, height: 24, resizeMode: 'contain'}} />
                                            )
                                        }
                                        {/* 圆点 */}
                                        { item.badge ? <View style={[styles.iconBadge, GStyle.badge]}><Text style={GStyle.badge_text}>{item.badge}</Text></View> : null }
                                        { item.badgeDot ? <View style={[styles.iconBadgeDot, GStyle.badge_dot]}></View> : null }
                                    </TouchableOpacity>
                                )
                            })
                        }
                    </View>
                </View>
            </View>
        )
    }

    goBack = () => {
        this.props.navigation.goBack()
    }
}

图片描述

图片描述

图片描述

图片描述

图片描述

图片描述

图片描述

图片描述

图片描述

图片描述

图片描述

App主页面及全局组件引入

import React, { Fragment, Component } from 'react'
import { StatusBar } from 'react-native'

// 引入公共js
import './src/utils/util'
import './src/utils/storage'

// 导入样式
import './src/assets/css/common'
// 导入rnPop弹窗
import './src/assets/js/rnPop/rnPop.js'

// 引入页面路由
import PageRouter from './src/router'

class App extends Component{
  render(){
    return (
      <Fragment>
        {/* <StatusBar backgroundColor={GStyle.headerBackgroundColor} barStyle='light-content' /> */}

        {/* 页面 */}
        <PageRouter />

        {/* 弹窗模板 */}
        <RNPop />
      </Fragment>
    )
  }
}

export default App

emoj表情符实现图文混排

faceList: [
	{
		nodes: [
			'?','?','?','?','?','?','?',
			'?','?','?','?','?','?','?',
			'?','?','?','?','?','?','del',
		]
	},
	{
		nodes: [
			'?','?','?','?','?','?','?',
			'?','?','?','?','?','?','?',
			'?','?','?','?','?','?','del',
		]
	},
	{
		nodes: [
			'?','?','?','?','?','?','?',
			'?','?','?','?','?','??','??',
			'??','??','?‍?','??‍?','??‍?','??‍✈️','del',
		]
	},
	...
]
/**
 * @desc 本地存储函数
 */

import AsyncStorage from '@react-native-community/async-storage'

export default class Storage{
    static get(key, callback){
        return AsyncStorage.getItem(key, (err, object) => {
            callback(err, JSON.parse(object))
        })
    }

    static set(key, data, callback){
        return AsyncStorage.setItem(key, JSON.stringify(data), callback)
    }

    static del(key){
        return AsyncStorage.removeItem(key)
    }

    static clear(){
        AsyncStorage.clear()
    }
}

global.storage = Storage

附上最近项目案例开发,希望能喜欢?? ~~~
vue网页版聊天室:https://cloud.tencent.com/developer/article/1420150
react网页聊天室:https://cloud.tencent.com/developer/article/1452667

点击查看更多内容
0人点赞

若觉得本文不错,就分享一下吧!

评论

相关文章推荐

正在加载中
意见反馈 邀请有奖 帮助中心 APP下载
官方微信

举报

0/150
提交
取消