File tree Expand file tree Collapse file tree 5 files changed +124
-9
lines changed
packages/react-native-actions
java/com/lucasbento/RNActions Expand file tree Collapse file tree 5 files changed +124
-9
lines changed Original file line number Diff line number Diff line change 1+
2+ buildscript {
3+ repositories {
4+ jcenter()
5+ }
6+
7+ dependencies {
8+ classpath ' com.android.tools.build:gradle:1.3.1'
9+ }
10+ }
11+
12+ apply plugin : ' com.android.library'
13+
14+ android {
15+ compileSdkVersion 23
16+ buildToolsVersion " 23.0.1"
17+
18+ defaultConfig {
19+ minSdkVersion 16
20+ targetSdkVersion 22
21+ versionCode 1
22+ versionName " 1.0"
23+ }
24+ lintOptions {
25+ abortOnError false
26+ }
27+ }
28+
29+ repositories {
30+ mavenCentral()
31+ }
32+
33+ dependencies {
34+ compile ' com.facebook.react:react-native:+'
35+ }
Original file line number Diff line number Diff line change 1+
2+ <manifest xmlns : android =" http://schemas.android.com/apk/res/android"
3+ package =" com.lucasbento.RNActions" >
4+
5+ </manifest >
6+
Original file line number Diff line number Diff line change 1+
2+ package com .lucasbento .RNActions ;
3+
4+ import com .facebook .react .ReactApplication ;
5+ import com .facebook .react .ReactInstanceManager ;
6+ import com .facebook .react .bridge .ReactApplicationContext ;
7+ import com .facebook .react .bridge .ReactContextBaseJavaModule ;
8+ import com .facebook .react .bridge .Promise ;
9+ import com .facebook .react .bridge .ReactMethod ;
10+ import com .facebook .react .devsupport .interfaces .DevSupportManager ;
11+
12+ import java .net .URL ;
13+
14+ public class RNActionsModule extends ReactContextBaseJavaModule {
15+
16+ private final ReactApplicationContext reactContext ;
17+
18+ public RNActionsModule (ReactApplicationContext reactContext ) {
19+ super (reactContext );
20+ this .reactContext = reactContext ;
21+ }
22+
23+ @ Override
24+ public String getName () {
25+ return "RNActions" ;
26+ }
27+
28+ private ReactInstanceManager getReactInstanceManager () {
29+ ReactApplication reactApplication = (ReactApplication )getCurrentActivity ().getApplication ();
30+ return reactApplication .getReactNativeHost ().getReactInstanceManager ();
31+ }
32+
33+ private DevSupportManager getDevSupportManager () {
34+ return getReactInstanceManager ().getDevSupportManager ();
35+ }
36+
37+ @ ReactMethod
38+ public void getHostUrl (final Promise promise ) {
39+ try {
40+ URL url = new URL (getDevSupportManager ().getSourceUrl ());
41+ String protocol = url .getProtocol ();
42+ String host = url .getHost ();
43+
44+ promise .resolve (String .format ("%s://%s" , protocol , host ));
45+ } catch (Exception e ) {
46+ promise .reject (e );
47+ }
48+ }
49+ }
Original file line number Diff line number Diff line change 1+
2+ package com .lucasbento .RNActions ;
3+
4+ import java .util .Arrays ;
5+ import java .util .Collections ;
6+ import java .util .List ;
7+
8+ import com .facebook .react .ReactPackage ;
9+ import com .facebook .react .bridge .NativeModule ;
10+ import com .facebook .react .bridge .ReactApplicationContext ;
11+ import com .facebook .react .uimanager .ViewManager ;
12+ import com .facebook .react .bridge .JavaScriptModule ;
13+
14+ public class RNActionsPackage implements ReactPackage {
15+ @ Override
16+ public List <NativeModule > createNativeModules (ReactApplicationContext reactContext ) {
17+ return Arrays .<NativeModule >asList (new RNActionsModule (reactContext ));
18+ }
19+
20+ // Deprecated from RN 0.47
21+ public List <Class <? extends JavaScriptModule >> createJSModules () {
22+ return Collections .emptyList ();
23+ }
24+
25+ @ Override
26+ public List <ViewManager > createViewManagers (ReactApplicationContext reactContext ) {
27+ return Collections .emptyList ();
28+ }
29+ }
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import config from './common/config';
88
99const DEFAULT_XMLHTTPREQUEST = GLOBAL . XMLHttpRequest ;
1010const isDev = __DEV__ ;
11+ const isIOS = Platform . OS === 'ios' ;
1112
1213const withActions = ( WrappedComponent ) => {
1314 class RNActions extends Component {
@@ -44,7 +45,7 @@ const withActions = (WrappedComponent) => {
4445 }
4546
4647 const { RNActions : NativeRNActions } = NativeModules ;
47-
48+
4849 NativeRNActions . getHostUrl ( )
4950 . then ( this . handleSetupSocket ) ;
5051 } ;
@@ -55,17 +56,12 @@ const withActions = (WrappedComponent) => {
5556 this . socket = io ( `${ url } :${ config . port } ` ) ;
5657
5758 const COMMANDS = {
58- ...Platform . select ( {
59- ios : {
60- reload : DevSettings . reload ,
61- openDevMenu : DevMenu . show ,
62- } ,
63- android : { } ,
64- } ) ,
59+ reload : isIOS && DevSettings . reload ,
60+ openDevMenu : isIOS && DevMenu . show ,
6561 toggleShowRequest : this . toggleShowRequest ,
6662 } ;
6763
68- this . socket . on ( 'action' , ( { type } ) => COMMANDS [ type ] ( ) ) ;
64+ this . socket . on ( 'action' , ( { type } ) => COMMANDS [ type ] && COMMANDS [ type ] ( ) ) ;
6965 } ;
7066
7167 handleUnmount = ( ) => this . socket . disconnect ( ) ;
You can’t perform that action at this time.
0 commit comments