Skip to content

Commit

Permalink
Merge pull request #122 from Microsoft/develop
Browse files Browse the repository at this point in the history
merge develop to master
  • Loading branch information
guperrot committed Sep 21, 2017
2 parents 320e619 + 9be5440 commit 641ce6c
Show file tree
Hide file tree
Showing 76 changed files with 1,530 additions and 740 deletions.
Empty file removed .gitmodules
Empty file.
2 changes: 2 additions & 0 deletions DemoApp/.eslintignore
@@ -0,0 +1,2 @@
node_modules/*
__tests__/*
34 changes: 34 additions & 0 deletions DemoApp/.eslintrc
@@ -0,0 +1,34 @@
{
"parser": "babel-eslint",
"env": {
"es6": true
},
"plugins": [
"react"
],
"extends": "airbnb",
"rules": {
"comma-dangle": 0,
"react/prop-types": 0,
"no-use-before-define": 0,
"radix": 0,
"no-param-reassign": 0,
"react/jsx-filename-extension": 0,
"no-mixed-operators": 0,
"import/prefer-default-export": 0,
"import/no-extraneous-dependencies": 0,
"no-plusplus": 0,
"react/prefer-stateless-function": 0,
"class-methods-use-this": 0,
"max-len": 0,
"jsx-a11y/href-no-hash": 0,
"indent": 0,
"import/no-unresolved": 0,
"no-console": 0,
"no-multi-spaces": [2, { "ignoreEOLComments": true }],
"func-names": 0,
"no-useless-escape": 0,
"import/no-dynamic-require": 0,
"react/sort-comp": 0
}
}
28 changes: 13 additions & 15 deletions DemoApp/AnalyticsScreen.js
Expand Up @@ -4,16 +4,12 @@
* @flow
*/

import React, { Component } from 'react';
import React from 'react';
import {
Alert,
AppRegistry,
StyleSheet,
Text,
View,
ScrollView,
TouchableOpacity,
NativeModules
TouchableOpacity
} from 'react-native';

import Analytics from 'mobile-center-analytics';
Expand All @@ -25,23 +21,24 @@ export default class AnalyticsScreen extends React.Component {
this.state = {
analyticsEnabled: false
};
this.toggleEnabled = this.toggleEnabled.bind(this);
}

async componentDidMount() {
let status = "";
const component = this;

const analyticsEnabled = await Analytics.isEnabled();
component.setState({ analyticsEnabled: analyticsEnabled });
component.setState({ analyticsEnabled });
}

async toggleEnabled() {
await Analytics.setEnabled(!this.state.analyticsEnabled);

const analyticsEnabled = await Analytics.isEnabled();
this.setState({ analyticsEnabled: analyticsEnabled });
this.setState({ analyticsEnabled });
}

/* eslint-disable no-undef */
render() {
return (
<View style={SharedStyles.container}>
Expand All @@ -51,34 +48,35 @@ export default class AnalyticsScreen extends React.Component {
</Text>

<Text style={SharedStyles.enabledText}>
Analytics enabled: {this.state.analyticsEnabled ? "yes" : "no"}
Analytics enabled: {this.state.analyticsEnabled ? 'yes' : 'no'}
</Text>
<TouchableOpacity onPress={this.toggleEnabled.bind(this)}>
<TouchableOpacity onPress={this.toggleEnabled}>
<Text style={SharedStyles.toggleEnabled}>
toggle
</Text>
</TouchableOpacity>

<TouchableOpacity onPress={() => Analytics.trackEvent("Button press", { page: "Home page" })}>
<TouchableOpacity onPress={() => Analytics.trackEvent('Button press', { page: 'Home page' })}>
<Text style={SharedStyles.button}>
Track Event
</Text>
</TouchableOpacity>

<TouchableOpacity onPress={() => Analytics.trackEvent("Button press", { propertyValueTooLong: "12345678901234567890123456789012345678901234567890123456789012345" })}>
<TouchableOpacity onPress={() => Analytics.trackEvent('Button press', { propertyValueTooLong: '12345678901234567890123456789012345678901234567890123456789012345' })}>
<Text style={SharedStyles.button}>
Track Event - event property value truncated after 64 characters
</Text>
</TouchableOpacity>

<TouchableOpacity onPress={() => Analytics.trackEvent("Button press", data)}>
<TouchableOpacity onPress={() => Analytics.trackEvent('Button press', data)}>
<Text style={SharedStyles.button}>
Track Event badly (Don't do this, only strings are supported)
Track Event badly (Do not do this, only strings are supported)
</Text>
</TouchableOpacity>

</ScrollView>
</View>
);
}
/* eslint-enable no-undef */
}
65 changes: 33 additions & 32 deletions DemoApp/CrashesScreen.js
Expand Up @@ -7,16 +7,13 @@
import React, { Component } from 'react';
import {
Alert,
Button,
StyleSheet,
Text,
View,
Switch,
ScrollView,
TouchableOpacity
} from 'react-native';

import { StackNavigator } from 'react-navigation';
import Crashes from 'mobile-center-crashes';
import { FooClass } from './js/FooClass';
import SharedStyles from './SharedStyles';
Expand All @@ -26,25 +23,29 @@ export default class CrashesScreen extends Component {
super();
this.state = {
crashesEnabled: false,
lastSessionStatus: "",
sendStatus: ""
lastSessionStatus: '',
sendStatus: ''
};
this.toggleEnabled = this.toggleEnabled.bind(this);
this.jsCrash = this.jsCrash.bind(this);
this.nativeCrash = this.nativeCrash.bind(this);
this.sendCrashes = this.sendCrashes.bind(this);
}

async componentDidMount() {
let status = "";
let status = '';
const component = this;

const crashesEnabled = await Crashes.isEnabled();
component.setState({ crashesEnabled: crashesEnabled });
component.setState({ crashesEnabled });

const crashedInLastSession = await Crashes.hasCrashedInLastSession();

status += `Crashed: ${crashedInLastSession ? "yes" : "no"}\n\n`;
status += `Crashed: ${crashedInLastSession ? 'yes' : 'no'}\n\n`;
component.setState({ lastSessionStatus: status });

if (crashedInLastSession) {
const crashReport = await Crashes.lastSessionCrashReport()
const crashReport = await Crashes.lastSessionCrashReport();

status += JSON.stringify(crashReport, null, 4);
component.setState({ lastSessionStatus: status });
Expand All @@ -55,11 +56,11 @@ export default class CrashesScreen extends Component {
await Crashes.setEnabled(!this.state.crashesEnabled);

const crashesEnabled = await Crashes.isEnabled();
this.setState({ crashesEnabled: crashesEnabled });
this.setState({ crashesEnabled });
}

jsCrash() {
var foo = new FooClass();
const foo = new FooClass();
foo.method1();
}

Expand All @@ -69,39 +70,39 @@ export default class CrashesScreen extends Component {

sendCrashes() {
const component = this;
Crashes.process(function (reports, send) {
let status = "";
Crashes.process((reports, send) => {
let status = '';

if (reports.length === 0) {
status += `Nothing to send\n`;
status += 'Nothing to send\n';
component.setState({ sendStatus: status });
return;
}

Crashes.setEventListener({
willSendCrash: function () {
status += `Will send crash\n`;
willSendCrash() {
status += 'Will send crash\n';
component.setState({ sendStatus: status });
},
didSendCrash: function () {
status += `Did send crash\n`;
didSendCrash() {
status += 'Did send crash\n';
component.setState({ sendStatus: status });
},
failedSendingCrash: function () {
status += `Failed sending crash\n`;
failedSendingCrash() {
status += 'Failed sending crash\n';
component.setState({ sendStatus: status });
}
});

let crashes = "";
for (const report of reports) {
let crashes = '';
reports.forEach((report) => {
if (crashes.length > 0) {
crashes += "\n\n";
crashes += '\n\n';
}
crashes += report.exceptionReason;
report.addTextAttachment("Hello attachment!", "hello.txt");
report.addBinaryAttachment(testIcon, "logo.png", "image/png");
}
report.addTextAttachment('Hello attachment!', 'hello.txt');
report.addBinaryAttachment(testIcon, 'logo.png', 'image/png');
});

Alert.alert(
`Send ${reports.length} crash(es)?`,
Expand All @@ -111,7 +112,7 @@ export default class CrashesScreen extends Component {
{ text: 'Ignore', onPress: () => send(false), style: 'cancel' },
]
);
}).then(() => console.log("Crashes were processed"));
}).then(() => console.log('Crashes were processed'));
}

render() {
Expand All @@ -123,26 +124,26 @@ export default class CrashesScreen extends Component {
</Text>

<Text style={SharedStyles.enabledText}>
Crashes enabled: {this.state.crashesEnabled ? "yes" : "no"}
Crashes enabled: {this.state.crashesEnabled ? 'yes' : 'no'}
</Text>
<TouchableOpacity onPress={this.toggleEnabled.bind(this)}>
<TouchableOpacity onPress={this.toggleEnabled}>
<Text style={SharedStyles.toggleEnabled}>
toggle
</Text>
</TouchableOpacity>

<TouchableOpacity onPress={this.jsCrash.bind(this)}>
<TouchableOpacity onPress={this.jsCrash}>
<Text style={styles.button}>
Crash JavaScript
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this.nativeCrash.bind(this)}>
<TouchableOpacity onPress={this.nativeCrash}>
<Text style={styles.button}>
Crash native code
</Text>
</TouchableOpacity>

<TouchableOpacity onPress={this.sendCrashes.bind(this)}>
<TouchableOpacity onPress={this.sendCrashes}>
<Text style={styles.button}>
Send crashes
</Text>
Expand Down
29 changes: 11 additions & 18 deletions DemoApp/MainScreen.js
Expand Up @@ -5,19 +5,15 @@
*/

import React, { Component } from 'react';
import { AppState, Alert, Button, Text, View, Platform, ToastAndroid } from 'react-native';
import SharedStyles from './SharedStyles';
import { AppState, Alert, Button, View, Platform, ToastAndroid } from 'react-native';
import Push from 'mobile-center-push';
import SharedStyles from './SharedStyles';

export default class MainScreen extends Component {
static navigationOptions = {
title: 'DemoApp',
};

constructor() {
super();
}

render() {
const { navigate } = this.props.navigation;

Expand Down Expand Up @@ -45,7 +41,7 @@ export default class MainScreen extends Component {
}
/>

<Button
<Button
title="Test Mobile Center"
onPress={() =>
navigate('MobileCenter')
Expand All @@ -58,39 +54,36 @@ export default class MainScreen extends Component {
}

Push.setEventListener({
pushNotificationReceived: function (pushNotification) {
pushNotificationReceived(pushNotification) {
let message = pushNotification.message;
let title = pushNotification.title;

if (message === null || message === undefined) {
// Android messages received in the background don't include a message. On Android, that fact can be used to
// check if the message was received in the background or foreground. For iOS the message is always present.
title = "Android background"
message = "<empty>"
title = 'Android background';
message = '<empty>';
}

// Any custom name/value pairs added in the portal are in customProperties
if (pushNotification.customProperties && Object.keys(pushNotification.customProperties).length > 0) {
message += '\nCustom properties:\n' + JSON.stringify(pushNotification.customProperties);
message += `\nCustom properties:\n${JSON.stringify(pushNotification.customProperties)}`;
}

if (AppState.currentState === 'active') {
Alert.alert(title, message);
}
else {
} else {
// Sometimes the push callback is received shortly before the app is fully active in the foreground.
// In this case you'll want to save off the notification info and wait until the app is fully shown
// in the foreground before displaying any UI. You could use AppState.addEventListener to be notified
// when the app is fully in the foreground.

// Showing an alert when not in the "active" state seems to work on iOS; for Android, we show a toast
// message instead
if (Platform.OS === "android") {
ToastAndroid.show('Notification while inactive:\n' + message, ToastAndroid.LONG);
}
else {
Alert.alert(title, message);
if (Platform.OS === 'android') {
ToastAndroid.show(`Notification while inactive:\n${message}`, ToastAndroid.LONG);
}
Alert.alert(title, message);
}
}
});

0 comments on commit 641ce6c

Please sign in to comment.