Skip to content

Commit

Permalink
Code push integration (#108)
Browse files Browse the repository at this point in the history
* Add react-native-code-push

* Add react-native-config

* Get code-push deployment keys from .env file using react-native-config

* Add code-push scripts

* Check for an update on app start

* Add manual checking for an update in Profile screen

* Add not applicable in debug mode message

* Add .env file (keys are for testing purposes only)

* Uhh, just use else statement

* For testing later

* Comment -out for testing

* Downgrade react-native-code-push version

* Move to auth-profile

* Fix orders

* Some code-push config

* Done testing

* Remove keys

* Use a ternary instead
  • Loading branch information
junedomingo authored and Houssein Djirdeh committed Jul 18, 2017
1 parent 2cf1e02 commit b538232
Show file tree
Hide file tree
Showing 12 changed files with 592 additions and 62 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CODEPUSH_ANDROID_DEPLOYMENT_KEY=
CODEPUSH_IOS_DEPLOYMENT_KEY=
10 changes: 10 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { persistStore } from 'redux-persist';
import createEncryptor from 'redux-persist-transform-encrypt';
import DeviceInfo from 'react-native-device-info';
import md5 from 'md5';
import codePush from 'react-native-code-push';

import { colors } from 'config';
import { GitPoint } from './routes';
Expand Down Expand Up @@ -57,6 +58,15 @@ class App extends Component {
);
}

componentDidMount() {
if (!__DEV__) {
codePush.sync({
updateDialog: false,
installMode: codePush.InstallMode.IMMEDIATE,
});
}
}

componentWillUpdate() {
LayoutAnimation.spring();
}
Expand Down
4 changes: 4 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ import com.android.build.OutputFile
*/

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

/**
* Set this to true to create two separate APKs instead of one:
Expand Down Expand Up @@ -133,6 +135,8 @@ android {
}

dependencies {
compile project(':react-native-config')
compile project(':react-native-code-push')
compile project(':react-native-device-info')
compile project(':react-native-vector-icons')
compile fileTree(dir: "libs", include: ["*.jar"])
Expand Down
10 changes: 10 additions & 0 deletions android/app/src/main/java/com/gitpoint/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.app.Application;

import com.facebook.react.ReactApplication;
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
import com.microsoft.codepush.react.CodePush;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactNativeHost;
Expand All @@ -16,6 +18,12 @@
public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}

@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
Expand All @@ -25,6 +33,8 @@ public boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactNativeConfigPackage(),
new CodePush(BuildConfig.CODEPUSH_ANDROID_DEPLOYMENT_KEY, MainApplication.this, BuildConfig.DEBUG),
new RNDeviceInfo(),
new VectorIconsPackage()
);
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string moduleConfig="true" name="reactNativeCodePush_androidDeploymentKey"></string>
<string name="app_name">GitPoint</string>
</resources>
4 changes: 4 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
rootProject.name = 'GitPoint'
include ':react-native-config'
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
include ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
include ':react-native-vector-icons'
Expand Down
103 changes: 101 additions & 2 deletions ios/GitPoint.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions ios/GitPoint/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#import "AppDelegate.h"
#import <CodePush/CodePush.h>

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
Expand All @@ -19,7 +20,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
{
NSURL *jsCodeLocation;


#ifdef DEBUG
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
#else
jsCodeLocation = [CodePush bundleURL];
#endif

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"GitPoint"
Expand Down
7 changes: 2 additions & 5 deletions ios/GitPoint/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@
<string>Octicons.ttf</string>
<string>SimpleLineIcons.ttf</string>
<string>Zocial.ttf</string>
<string>OpenSans-Bold.ttf</string>
<string>OpenSans-Light.ttf</string>
<string>OpenSans-Regular.ttf</string>
<string>OpenSans-Semibold.ttf</string>
<string>Menlo.ttf</string>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
Expand All @@ -87,5 +82,7 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CodePushDeploymentKey</key>
<string>__RN_CONFIG_CODEPUSH_IOS_DEPLOYMENT_KEY</string>
</dict>
</plist>
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
"flow-stop": "flow stop",
"flow-status": "flow status",
"flow-coverage": "flow coverage",
"contributors:add": "all-contributors add"
"contributors:add": "all-contributors add",
"cp-release:ios": "code-push release-react git-point-ios ios",
"cp-release:android": "code-push release-react git-point-android android",
"cp-promote:ios": "code-push promote git-point-ios Staging Production",
"cp-promote:android": "code-push promote git-point-android Staging Production",
"cp-history:ios-staging": "code-push deployment history git-point-ios Staging",
"cp-history:android-staging": "code-push deployment history git-point-android Staging",
"cp-history:android-production": "code-push deployment history git-point-android Production",
"cp-history:ios-production": "code-push deployment history git-point-ios Production"
},
"lint-staged": {
"*.js": [
Expand All @@ -39,7 +47,9 @@
"react": "16.0.0-alpha.12",
"react-native": "0.46.2",
"react-native-actionsheet": "^2.2.0",
"react-native-code-push": "3.0.1-beta",
"react-native-communications": "^2.2.1",
"react-native-config": "^0.5.0",
"react-native-device-info": "^0.10.2",
"react-native-elements": "^0.9.3",
"react-native-htmlview": "^0.9.0",
Expand All @@ -63,6 +73,7 @@
"babel-eslint": "^7.1.1",
"babel-jest": "18.0.0",
"babel-plugin-module-resolver": "^2.7.1",
"babel-plugin-transform-inline-environment-variables": "^6.8.0",
"babel-preset-flow": "^6.23.0",
"babel-preset-react-native": "1.9.1",
"eslint": "^3.19.0",
Expand All @@ -79,8 +90,7 @@
"lint-staged": "^3.2.6",
"pre-commit": "^1.2.2",
"prettier": "^1.3.1",
"react-test-renderer": "16.0.0-alpha.6",
"babel-plugin-transform-inline-environment-variables": "^6.8.0"
"react-test-renderer": "16.0.0-alpha.6"
},
"jest": {
"preset": "react-native"
Expand Down
54 changes: 53 additions & 1 deletion src/auth/screens/auth-profile.screen.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { StyleSheet } from 'react-native';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { ListItem } from 'react-native-elements';
import codePush from 'react-native-code-push';

import {
ViewContainer,
Expand Down Expand Up @@ -36,8 +37,28 @@ const styles = StyleSheet.create({
color: colors.greyDark,
...fonts.fontPrimary,
},
update: {
flex: 1,
alignItems: 'center',
marginVertical: 40,
},
updateText: {
color: colors.grey,
fontFamily: 'AvenirNext-Medium',
},
updateTextSub: {
fontSize: 11,
},
});

const updateText = {
check: 'Check for update',
checking: 'Checking for update...',
updated: 'App is up to date',
available: 'Update is available!',
notApplicable: 'Not applicable in debug mode',
};

class AuthProfile extends Component {
props: {
getUser: Function,
Expand All @@ -49,11 +70,33 @@ class AuthProfile extends Component {
navigation: Object,
};

state = {
updateText: updateText.check,
};

componentDidMount() {
this.props.getUser();
this.props.getOrgs();
}

checkForUpdate = () => {
if (__DEV__) {
this.setState({ updateText: updateText.notApplicable });
} else {
this.setState({ updateText: updateText.checking });
codePush
.sync({
updateDialog: true,
installMode: codePush.InstallMode.IMMEDIATE,
})
.then(update => {
this.setState({
updateText: update ? updateText.available : updateText.updated,
});
});
}
};

render() {
const { user, orgs, isPendingUser, isPendingOrgs, navigation } = this.props;
const loading = isPendingUser || isPendingOrgs;
Expand Down Expand Up @@ -98,6 +141,15 @@ class AuthProfile extends Component {
/>
)}
</SectionList>

<View style={styles.update}>
<Text style={styles.updateText}>GitPoint v1.1</Text>
<TouchableOpacity onPress={this.checkForUpdate}>
<Text style={[styles.updateText, styles.updateTextSub]}>
{this.state.updateText}
</Text>
</TouchableOpacity>
</View>
</ParallaxScroll>}
</ViewContainer>
);
Expand Down
Loading

0 comments on commit b538232

Please sign in to comment.