-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.android.js
More file actions
170 lines (154 loc) · 5.73 KB
/
index.android.js
File metadata and controls
170 lines (154 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
ViewPagerAndroid,
TouchableHighlight,
ListView,
TextInput,
BackAndroid,
NativeAppEventEmitter,
NativeModules
} from 'react-native';
var MakemojiTextInput = require('./MakemojiRN/MakemojiTextInput');// MakemojiTextInput from './MakemojiRN/MakemojiTextInput'
var MakemojiReactions = require('./MakemojiRN/MakemojiReactions');
import MakemojiEditTextAndroid from './MakemojiRN/MakemojiEditTextAndroid'
import MakemojiTextAndroid from './MakemojiRN/MakemojiTextAndroid'
const NativeEventEmitter = require('NativeEventEmitter');
const showDetatchControls = true; // enable to show example of detached input.
class MakemojiReactNative extends Component {
constructor(props){
super(props);
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {htmlMessages:[],
dataSource:ds.cloneWithRows([]),
outsideEditText:' ',
showReactions:false,
textSize:17.0};
}
componentWillUnmount(){
this.subscription.remove();
this.wallSubscription.remove();
BackAndroid.removeEventListener(this.backListener);
}
componentWillMount(){
NativeModules.MakemojiManager.init("yourkey");
var emitter = new NativeEventEmitter(NativeModules.MakemojiManager);
this.subscription = emitter.addListener(
'onHypermojiPress',
(event) => console.log(event.url)
);
this.wallSubscription = emitter.addListener(
'onEmojiWallSelect',
(event) => console.log(event)
);
this.backListener = BackAndroid.addEventListener('hardwareBackPress', () => {
if (this.refs.mojiInput && this.refs.mojiInput.canGoBack()){
this.refs.mojiInput.onBackPressed();
return true;//back handled
}
return false;
});
}
render() {
return (
<View keyboardShouldPersistTaps={false} style={styles.container}>
{showDetatchControls? <View>
<MakemojiEditTextAndroid keyboardShouldPersistTaps={false} style={[styles.editText,{fontSize:this.state.textSize}]}
finderTag={'topEditText'} ref={'topEditText'} onHtmlGenerated={this.sendPressed.bind(this)}/>
<TouchableHighlight onPress={this.genHtml.bind(this)}>
<Text style={styles.welcome} selectable={true}>
Grab Text from top edit text.
</Text>
</TouchableHighlight>
<TouchableHighlight onPress={() =>this.setState({outsideEditText:'topEditText'})}>
<Text style={styles.instructions}>
Attatch Edit Text
</Text>
</TouchableHighlight>
<TouchableHighlight onPress={() => this.setState({outsideEditText:null})}>
<Text style={styles.instructions}>
Detatch Edit Text
</Text>
</TouchableHighlight>
<View style={{flexDirection:'row',justifyContent:'center'}}>
<TouchableHighlight onPress={() => NativeModules.MakemojiManager.openWall()}>
<Text style={[{marginTop:5},styles.instructions]}>
Wall
</Text>
</TouchableHighlight>
<TouchableHighlight onPress={() => this.setState({showReactions:!this.state.showReactions})}>
<Text style={[{marginTop:5,marginLeft:30},styles.instructions]}>
{this.state.showReactions?'-Reactions':'+Reactions'}
</Text>
</TouchableHighlight>
</View>
</View> :null}
<ListView style={{flex:1,alignSelf:'stretch'}}
dataSource={this.state.dataSource}
enableEmptySections={true}
renderRow={(rowData) => <View style={{flexDirection:'column'}}>
<MakemojiTextAndroid style={styles.instructions} html={rowData}/>
{this.state.showReactions? <MakemojiReactions style={styles.reaction} contentId={rowData}/> :null}
</View>}
/>
<MakemojiTextInput outsideEditText={this.state.outsideEditText} ref={'mojiInput'} style={styles.moji} alwaysShowEmojiBar={false}
onSendPress={this.sendPressed.bind(this)} onCameraPress={this.log}/>
</View>
);
}
genHtml(){
this.refs.topEditText.requestHtml(true,true);//args:should clear input;should send text to analytics
}
sendPressed(sendObject){
console.log('send pressed', sendObject);
var htmlMessages = [...this.state.htmlMessages,sendObject.html];
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.setState({htmlMessages:htmlMessages,dataSource:ds.cloneWithRows(htmlMessages)});
//this.refs.topEditText.setText(sendObject.plaintext);
}
log(event){
console.log('',event);
}
}
const styles = StyleSheet.create({
reaction:{
height:30,
alignSelf: 'stretch',
},
editText:{
height:50,
alignSelf: 'stretch',
},
container: {
flex: 1,
flexDirection:'column',
justifyContent: 'flex-end',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
fontSize:18,
height:30
},
moji:{
height:100,
justifyContent: 'flex-end',
alignSelf: 'stretch'
}
});
AppRegistry.registerComponent('MakemojiReactNative', () => MakemojiReactNative);