Clean up the sampleApp

This commit is contained in:
DevHossamHassan 2017-07-09 15:50:52 +02:00
parent e0639feaa0
commit ac12541a7f

View File

@ -14,12 +14,10 @@ import {
processColor,
Aerlt,
Image,
ListView,
TouchableHighlight,
RecyclerViewBackedScrollView
} from "react-native";
import Instabug from "instabug-reactnative";
let DialogAndroid = require('react-native-dialogs');
export default class InstabugSample extends Component {
@ -30,294 +28,52 @@ export default class InstabugSample extends Component {
Instabug.setPrimaryColor(processColor('#aaff00'));
Instabug.setEmailFieldRequired(false);
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
dataSource: ds.cloneWithRows(this._genRows({})),
};
}
_renderRow(rowData, sectionID, rowID, highlightRow) {
const that = this;
return (
<TouchableHighlight onPress={() => {
that._pressRow(rowID);
highlightRow(sectionID, rowID);
}}>
<View>
<View style={styles.row}>
<Text style={styles.text}>
{rowData}
</Text>
</View>
</View>
</TouchableHighlight>
);
}
_genRows() {
var dataBlob = [
"Invoke",
"Invoke with invocation mode",
"Select invocation event",
"Show intro message",
"Unread messages count",
"Set locale",
"Set color theme",
"Set primary color"
];
return dataBlob;
}
_pressRow(rowID) {
if (rowID == 0) {
Instabug.invoke();
} else if (rowID == 1) {
this._showInvocationModeActionSheet();
} else if (rowID == 2) {
this._showInvocationEventActionSheet();
} else if (rowID == 3) {
Instabug.showIntroMessage();
} else if (rowID == 4) {
Instabug.getUnreadMessagesCount((count) => {
Alert.alert("UnReadMessages", "Messages: " + count);
});
} else if (rowID == 5) {
this._showLocaleActionSheet();
} else if (rowID == 6) {
this._showColorThemeActionSheet();
} else if (rowID == 7) {
this._showPrimaryColorActionSheet();
}
}
_showInvocationModeActionSheet() {
let options = {
"items": [
"New bug",
"New Feedback",
"New Chat",
"None"
],
"title": "Instabug modes",
itemsCallback: (id, text) => {
if (id == 0) {
Instabug.invokeWithInvocationMode(Instabug.invocationMode.newBug);
} else if (id == 1) {
Instabug.invokeWithInvocationMode(Instabug.invocationMode.newFeedback);
} else if (id == 2) {
Instabug.invokeWithInvocationMode(Instabug.invocationMode.newChat);
} else if (id == 3) {
Instabug.invokeWithInvocationMode(Instabug.invocationMode.NA);
}
}
};
showDialog = function () {
let dialog = new DialogAndroid();
dialog.set(options);
dialog.show();
};
showDialog();
}
_showColorThemeActionSheet() {
let options = {
"items": [
"Light",
"Dark"
],
"title": "Instabug Themes",
itemsCallback: (id, text) => {
if (id == 0) {
Instabug.setColorTheme(Instabug.colorTheme.light);
} else if (id == 1) {
Instabug.setColorTheme(Instabug.colorTheme.dark);
}
}
};
showDialog = function () {
let dialog = new DialogAndroid();
dialog.set(options);
dialog.show();
};
showDialog();
}
_showPrimaryColorActionSheet() {
let options = {
"items": [
"Red",
"Green",
"Blue"
],
"title": "Instabug Primary Color",
itemsCallback: (id, text) => {
if (id == 0) {
Instabug.setPrimaryColor(processColor('#ff0000'));
} else if (id == 1) {
Instabug.setPrimaryColor(processColor('#00ff00'));
} else if (id == 2) {
Instabug.setPrimaryColor(processColor('#0000ff'));
}
}
};
showDialog = function () {
let dialog = new DialogAndroid();
dialog.set(options);
dialog.show();
};
showDialog();
}
_showLocaleActionSheet() {
let options = {
"items": [
"Arabic",
"Chinese Simplified",
"Chinese Traditional",
"Czech",
"Danish",
"English",
"French",
"German",
"Italian",
"Japanese",
"Polish",
"Portuguese Brazil",
"Russian",
"Spanish",
"Swedish",
"Turkish"
],
"title": "Instabug Primary Color",
itemsCallback: (id, text) => {
if (id == 0) {
Instabug.setLocale(Instabug.locale.arabic);
} else if (id == 1) {
Instabug.setLocale(Instabug.locale.chineseSimplified);
} else if (id == 2) {
Instabug.setLocale(Instabug.locale.chineseTraditional);
} else if (id == 3) {
Instabug.setLocale(Instabug.locale.czech);
} else if (id == 4) {
Instabug.setLocale(Instabug.locale.danish);
} else if (id == 5) {
Instabug.setLocale(Instabug.locale.english);
} else if (id == 6) {
Instabug.setLocale(Instabug.locale.french);
} else if (id == 7) {
Instabug.setLocale(Instabug.locale.german);
} else if (id == 8) {
Instabug.setLocale(Instabug.locale.italian);
} else if (id == 9) {
Instabug.setLocale(Instabug.locale.japanese);
} else if (id == 10) {
Instabug.setLocale(Instabug.locale.polish);
} else if (id == 11) {
Instabug.setLocale(Instabug.locale.portugueseBrazil);
} else if (id == 12) {
Instabug.setLocale(Instabug.locale.russian);
} else if (id == 13) {
Instabug.setLocale(Instabug.locale.spanish);
} else if (id == 14) {
Instabug.setLocale(Instabug.locale.swedish);
} else if (id == 15) {
Instabug.setLocale(Instabug.locale.turkish);
}
}
};
showDialog = function () {
let dialog = new DialogAndroid();
dialog.set(options);
dialog.show();
};
showDialog();
}
_showInvocationEventActionSheet() {
let options = {
"items": [
"Shake",
"Screenshot",
"Two fingers swipe",
"Floating button"
],
"title": "Instabug Themes",
itemsCallback: (id, text) => {
if (id == 0) {
Instabug.setInvocationEvent(Instabug.invocationEvent.shake);
} else if (id == 1) {
Instabug.setInvocationEvent(Instabug.invocationEvent.screenshot);
} else if (id == 2) {
Instabug.setInvocationEvent(Instabug.invocationEvent.twoFingersSwipe);
} else if (id) {
Instabug.setInvocationEvent(Instabug.invocationEvent.floatingButton);
}
}
};
showDialog = function () {
let dialog = new DialogAndroid();
dialog.set(options);
dialog.show();
};
showDialog();
}
_renderSeparator(sectionID, rowID, adjacentRowHighlighted) {
return (
<View
key={`${sectionID}-${rowID}`}
style={{
height: adjacentRowHighlighted ? 4 : 1,
backgroundColor: adjacentRowHighlighted ? '#3B5998' : '#CCCCCC',
}}
/>
);
}
render() {
console.log(JSON.stringify(this.state));
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderRow.bind(this)}
renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}
style={styles.listView}
/>
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.android.js
</Text>
<Text style={styles.instructions}>
Double tap R on your keyboard to reload,{'\n'}
Shake or press menu button for dev menu
</Text>
<Button
onPress={() => {
console.log("invoke Button has been clicked");
Instabug.invoke()}}
title="Invoke Instabug"
color="#841584"
disabled={false}
accessibilityLabel="Learn more about this purple button"
/>
</View>
);
}
}
const styles = StyleSheet.create({
row: {
flexDirection: 'row',
justifyContent: 'center',
padding: 10,
backgroundColor: '#F6F6F6',
},
thumb: {
width: 64,
height: 64,
},
text: {
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
listView: {
paddingTop: 20
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});