react native實現的仿微信原生app聊天實例,基於react-native+react-navigation+react+redux+react-native-image-picker+react-native-swiper等技術架構開發。實現了消息發送、textInput文本框插入表情符、表情大圖gif、圖片選擇預覽、紅包、朋友圈等功能。html
{ "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導航器不能知足項目需求,如是就基於react-navigation導航器自定義個頂部導航條headerBar組件
html5
//右側圖標(文字) <HeaderBar navigation={this.props.navigation} title='新的朋友' headerRight={[ { title: '添加好友', style: {color: '#fff', fontSize: 14}, press: this.handlePress01 } ]} /> //右側圖標(iconfont) <HeaderBar navigation={this.props.navigation} title='標題信息' headerRight={[ { title: (<Text style={[GStyle.iconfont, GStyle.c_fff, GStyle.fs_18]}></Text>), type: 'iconfont', press: this.handlePress01 } ]} /> //右側圖標(圖片) <HeaderBar navigation={this.props.navigation} search headerRight={[ { title: require('../../assets/img/search.png'), press: this.handlePress01 }, { title: require('../../assets/img/add.png'), press: this.handlePress02 }, ]} />
/** * @desc 啓動頁面 */ import React, { Component } from 'react' import { StatusBar, Animated, View, Text, Image } from 'react-native' export default class Splash extends Component{ constructor(props){ super(props) this.state = { animFadeIn: new Animated.Value(0), animFadeOut: new Animated.Value(1), } } render(){ return ( <Animated.View style={[GStyle.flex1DC_a_j, {backgroundColor: '#1a4065', opacity: this.state.animFadeOut}]}> <StatusBar backgroundColor='transparent' barStyle='light-content' translucent={true} /> <View style={GStyle.flex1_a_j}> <Image source={require('../assets/img/ic_default.jpg')} style={{borderRadius: 100, width: 100, height: 100}} /> </View> <View style={[GStyle.align_c, {paddingVertical: 20}]}> <Text style={{color: '#dbdbdb', fontSize: 12, textAlign: 'center',}}>RN-ChatRoom v1.0.0</Text> </View> </Animated.View> ) } componentDidMount(){ // 判斷是否登陸 storage.get('hasLogin', (err, object) => { setTimeout(() => { Animated.timing( this.state.animFadeOut, {duration: 300, toValue: 0} ).start(()=>{ // 跳轉頁面 util.navigationReset(this.props.navigation, (!err && object && object.hasLogin) ? 'Index' : 'Login') }) }, 1500); }) } }
表情則是使用的emoj表情符,因爲使用image表情的話,處理起來麻煩,也影響系統性能。node
faceList: [ { 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
最後附上以前開發的H5即時IM項目,但願能喜歡😍😍 ^-^
html5即時webIM實例:https://segmentfault.com/a/11...react