|
4 | 4 | * @flow
|
5 | 5 | */
|
6 | 6 |
|
7 |
| -import React, { Component } from 'react'; |
| 7 | +import React, {Component} from 'react'; |
8 | 8 | import {
|
9 |
| - AppRegistry, |
10 |
| - StyleSheet, |
11 |
| - Text, |
12 |
| - View |
| 9 | + AppRegistry, |
| 10 | + StyleSheet, |
| 11 | + Text, |
| 12 | + Button, |
| 13 | + Alert, |
| 14 | + View, |
| 15 | + processColor, |
| 16 | + Aerlt, |
| 17 | + Image, |
| 18 | + ListView, |
| 19 | + TouchableHighlight, |
| 20 | + RecyclerViewBackedScrollView, |
13 | 21 | } from 'react-native';
|
14 | 22 |
|
| 23 | +import Instabug from'instabug-reactnative'; |
| 24 | +let DialogAndroid = require('react-native-dialogs'); |
| 25 | + |
15 | 26 | export default class InstabugSample extends Component {
|
16 |
| - render() { |
17 |
| - return ( |
18 |
| - <View style={styles.container}> |
19 |
| - <Text style={styles.welcome}> |
20 |
| - Welcome to React Native! |
21 |
| - </Text> |
22 |
| - <Text style={styles.instructions}> |
23 |
| - To get started, edit index.android.js |
24 |
| - </Text> |
25 |
| - <Text style={styles.instructions}> |
26 |
| - Double tap R on your keyboard to reload,{'\n'} |
27 |
| - Shake or press menu button for dev menu |
28 |
| - </Text> |
29 |
| - </View> |
30 |
| - ); |
31 |
| - } |
| 27 | + |
| 28 | + constructor(props) { |
| 29 | + super(props); |
| 30 | + Instabug.startWithToken('0f0dc916bd9175e3b5d2fdf0cfa49a69', |
| 31 | + Instabug.invocationEvent.floatingButton); |
| 32 | + const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); |
| 33 | + this.state = { |
| 34 | + dataSource: ds.cloneWithRows(this._genRows({})), |
| 35 | + }; |
| 36 | + } |
| 37 | + |
| 38 | + _renderRow(rowData, sectionID, rowID, highlightRow) { |
| 39 | + const that = this; |
| 40 | + return ( |
| 41 | + <TouchableHighlight onPress={() => { |
| 42 | + that._pressRow(rowID); |
| 43 | + highlightRow(sectionID, rowID); |
| 44 | + }}> |
| 45 | + <View> |
| 46 | + <View style={styles.row}> |
| 47 | + <Text style={styles.text}> |
| 48 | + {rowData} |
| 49 | + </Text> |
| 50 | + </View> |
| 51 | + </View> |
| 52 | + </TouchableHighlight> |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + _genRows() { |
| 57 | + var dataBlob = [ |
| 58 | + "Invoke", |
| 59 | + "Invoke with invocation mode", |
| 60 | + "Select invocation event", |
| 61 | + "Show intro message", |
| 62 | + "Unread messages count", |
| 63 | + "Set locale", |
| 64 | + "Set color theme", |
| 65 | + "Set primary color" |
| 66 | + ]; |
| 67 | + return dataBlob; |
| 68 | + } |
| 69 | + |
| 70 | + _pressRow(rowID) { |
| 71 | + if (rowID == 0) { |
| 72 | + Instabug.invoke(); |
| 73 | + } else if (rowID == 1) { |
| 74 | + this._showInvocationModeActionSheet(); |
| 75 | + } else if (rowID == 2) { |
| 76 | + this._showInvocationEventActionSheet(); |
| 77 | + } else if (rowID == 3) { |
| 78 | + Instabug.showIntroMessage(); |
| 79 | + } else if (rowID == 4) { |
| 80 | + Alert.alert("UnReadMessages", "Messages: " + |
| 81 | + Instabug.getUnreadMessagesCount()); |
| 82 | + } else if (rowID == 5) { |
| 83 | + this._showLocaleActionSheet(); |
| 84 | + } else if (rowID == 6) { |
| 85 | + this._showColorThemeActionSheet(); |
| 86 | + } else if (rowID == 7) { |
| 87 | + this._showPrimaryColorActionSheet(); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + _showInvocationModeActionSheet() { |
| 92 | + let options = { |
| 93 | + "items": [ |
| 94 | + "New bug", |
| 95 | + "New Feedback", |
| 96 | + "New Chat", |
| 97 | + "None" |
| 98 | + ], |
| 99 | + "title": "Instabug modes", |
| 100 | + itemsCallback: (id, text) => { |
| 101 | + if (id == 0) { |
| 102 | + Instabug.invokeWithInvocationMode(Instabug.invocationMode.newBug); |
| 103 | + } else if (id == 1) { |
| 104 | + Instabug.invokeWithInvocationMode(Instabug.invocationMode.newFeedback); |
| 105 | + } else if (id == 2) { |
| 106 | + Instabug.invokeWithInvocationMode(Instabug.invocationMode.newChat); |
| 107 | + } else if (id == 3) { |
| 108 | + Instabug.invokeWithInvocationMode(Instabug.invocationMode.NA); |
| 109 | + } |
| 110 | + } |
| 111 | + }; |
| 112 | + |
| 113 | + showDialog = function () { |
| 114 | + let dialog = new DialogAndroid(); |
| 115 | + dialog.set(options); |
| 116 | + dialog.show(); |
| 117 | + }; |
| 118 | + |
| 119 | + showDialog(); |
| 120 | + } |
| 121 | + |
| 122 | + _showColorThemeActionSheet() { |
| 123 | + let options = { |
| 124 | + "items": [ |
| 125 | + "Light", |
| 126 | + "Dark" |
| 127 | + ], |
| 128 | + "title": "Instabug Themes", |
| 129 | + itemsCallback: (id, text) => { |
| 130 | + if (id == 0) { |
| 131 | + Instabug.setColorTheme(Instabug.colorTheme.light); |
| 132 | + } else if (id == 1) { |
| 133 | + Instabug.setColorTheme(Instabug.colorTheme.dark); |
| 134 | + } |
| 135 | + } |
| 136 | + }; |
| 137 | + |
| 138 | + showDialog = function () { |
| 139 | + let dialog = new DialogAndroid(); |
| 140 | + dialog.set(options); |
| 141 | + dialog.show(); |
| 142 | + }; |
| 143 | + |
| 144 | + showDialog(); |
| 145 | + } |
| 146 | + |
| 147 | + _showPrimaryColorActionSheet() { |
| 148 | + let options = { |
| 149 | + "items": [ |
| 150 | + "Red", |
| 151 | + "Green", |
| 152 | + "Blue" |
| 153 | + ], |
| 154 | + "title": "Instabug Primary Color", |
| 155 | + itemsCallback: (id, text) => { |
| 156 | + if (id == 0) { |
| 157 | + Instabug.setPrimaryColor(processColor('#ff0000')); |
| 158 | + } else if (id == 1) { |
| 159 | + Instabug.setPrimaryColor(processColor('#00ff00')); |
| 160 | + } else if (id == 2) { |
| 161 | + Instabug.setPrimaryColor(processColor('#0000ff')); |
| 162 | + } |
| 163 | + } |
| 164 | + }; |
| 165 | + |
| 166 | + showDialog = function () { |
| 167 | + let dialog = new DialogAndroid(); |
| 168 | + dialog.set(options); |
| 169 | + dialog.show(); |
| 170 | + }; |
| 171 | + |
| 172 | + showDialog(); |
| 173 | + } |
| 174 | + |
| 175 | + _showLocaleActionSheet() { |
| 176 | + |
| 177 | + let options = { |
| 178 | + "items": [ |
| 179 | + "Arabic", |
| 180 | + "Chinese Simplified", |
| 181 | + "Chinese Traditional", |
| 182 | + "Czech", |
| 183 | + "Danish", |
| 184 | + "English", |
| 185 | + "French", |
| 186 | + "German", |
| 187 | + "Italian", |
| 188 | + "Japanese", |
| 189 | + "Polish", |
| 190 | + "Portuguese Brazil", |
| 191 | + "Russian", |
| 192 | + "Spanish", |
| 193 | + "Swedish", |
| 194 | + "Turkish" |
| 195 | + ], |
| 196 | + "title": "Instabug Primary Color", |
| 197 | + itemsCallback: (id, text) => { |
| 198 | + if (id == 0) { |
| 199 | + Instabug.setLocale(Instabug.locale.arabic); |
| 200 | + } else if (id == 1) { |
| 201 | + Instabug.setLocale(Instabug.locale.chineseSimplified); |
| 202 | + } else if (id == 2) { |
| 203 | + Instabug.setLocale(Instabug.locale.chineseTraditional); |
| 204 | + } else if (id == 3) { |
| 205 | + Instabug.setLocale(Instabug.locale.czech); |
| 206 | + } else if (id == 4) { |
| 207 | + Instabug.setLocale(Instabug.locale.danish); |
| 208 | + } else if (id == 5) { |
| 209 | + Instabug.setLocale(Instabug.locale.english); |
| 210 | + } else if (id == 6) { |
| 211 | + Instabug.setLocale(Instabug.locale.french); |
| 212 | + } else if (id == 7) { |
| 213 | + Instabug.setLocale(Instabug.locale.german); |
| 214 | + } else if (id == 8) { |
| 215 | + Instabug.setLocale(Instabug.locale.italian); |
| 216 | + } else if (id == 9) { |
| 217 | + Instabug.setLocale(Instabug.locale.japanese); |
| 218 | + } else if (id == 10) { |
| 219 | + Instabug.setLocale(Instabug.locale.polish); |
| 220 | + } else if (id == 11) { |
| 221 | + Instabug.setLocale(Instabug.locale.portugueseBrazil); |
| 222 | + } else if (id == 12) { |
| 223 | + Instabug.setLocale(Instabug.locale.russian); |
| 224 | + } else if (id == 13) { |
| 225 | + Instabug.setLocale(Instabug.locale.spanish); |
| 226 | + } else if (id == 14) { |
| 227 | + Instabug.setLocale(Instabug.locale.swedish); |
| 228 | + } else if (id == 15) { |
| 229 | + Instabug.setLocale(Instabug.locale.turkish); |
| 230 | + } |
| 231 | + } |
| 232 | + }; |
| 233 | + |
| 234 | + showDialog = function () { |
| 235 | + let dialog = new DialogAndroid(); |
| 236 | + dialog.set(options); |
| 237 | + dialog.show(); |
| 238 | + }; |
| 239 | + |
| 240 | + showDialog(); |
| 241 | + } |
| 242 | + |
| 243 | + _showInvocationEventActionSheet() { |
| 244 | + |
| 245 | + |
| 246 | + let options = { |
| 247 | + "items": [ |
| 248 | + "Shake", |
| 249 | + "Screenshot", |
| 250 | + "Two fingers swipe", |
| 251 | + "Floating button" |
| 252 | + ], |
| 253 | + "title": "Instabug Themes", |
| 254 | + itemsCallback: (id, text) => { |
| 255 | + if (id == 0) { |
| 256 | + Instabug.setInvocationEvent(Instabug.invocationEvent.shake); |
| 257 | + } else if (id == 1) { |
| 258 | + Instabug.setInvocationEvent(Instabug.invocationEvent.screenshot); |
| 259 | + } else if (id == 2) { |
| 260 | + Instabug.setInvocationEvent(Instabug.invocationEvent.twoFingersSwipe); |
| 261 | + } else if (id) { |
| 262 | + Instabug.setInvocationEvent(Instabug.invocationEvent.floatingButton); |
| 263 | + } |
| 264 | + } |
| 265 | + }; |
| 266 | + |
| 267 | + showDialog = function () { |
| 268 | + let dialog = new DialogAndroid(); |
| 269 | + dialog.set(options); |
| 270 | + dialog.show(); |
| 271 | + }; |
| 272 | + |
| 273 | + showDialog(); |
| 274 | + } |
| 275 | + |
| 276 | + _renderSeparator(sectionID, rowID, adjacentRowHighlighted) { |
| 277 | + return ( |
| 278 | + <View |
| 279 | + key={`${sectionID}-${rowID}`} |
| 280 | + style={{ |
| 281 | + height: adjacentRowHighlighted ? 4 : 1, |
| 282 | + backgroundColor: adjacentRowHighlighted ? '#3B5998' : '#CCCCCC', |
| 283 | + }} |
| 284 | + /> |
| 285 | + ); |
| 286 | + } |
| 287 | + |
| 288 | + render() { |
| 289 | + console.log(JSON.stringify(this.state)); |
| 290 | + return ( |
| 291 | + <ListView |
| 292 | + dataSource={this.state.dataSource} |
| 293 | + renderRow={this._renderRow.bind(this)} |
| 294 | + renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />} |
| 295 | + style={styles.listView} |
| 296 | + /> |
| 297 | + ); |
| 298 | + } |
32 | 299 | }
|
33 | 300 |
|
34 | 301 | const styles = StyleSheet.create({
|
35 |
| - container: { |
36 |
| - flex: 1, |
37 |
| - justifyContent: 'center', |
38 |
| - alignItems: 'center', |
39 |
| - backgroundColor: '#F5FCFF', |
40 |
| - }, |
41 |
| - welcome: { |
42 |
| - fontSize: 20, |
43 |
| - textAlign: 'center', |
44 |
| - margin: 10, |
45 |
| - }, |
46 |
| - instructions: { |
47 |
| - textAlign: 'center', |
48 |
| - color: '#333333', |
49 |
| - marginBottom: 5, |
50 |
| - }, |
| 302 | + row: { |
| 303 | + flexDirection: 'row', |
| 304 | + justifyContent: 'center', |
| 305 | + padding: 10, |
| 306 | + backgroundColor: '#F6F6F6', |
| 307 | + }, |
| 308 | + thumb: { |
| 309 | + width: 64, |
| 310 | + height: 64, |
| 311 | + }, |
| 312 | + text: { |
| 313 | + flex: 1, |
| 314 | + }, |
| 315 | + listView: { |
| 316 | + paddingTop: 20 |
| 317 | + }, |
51 | 318 | });
|
52 | 319 |
|
53 | 320 | AppRegistry.registerComponent('InstabugSample', () => InstabugSample);
|
0 commit comments