Skip to content

Commit

Permalink
Fix Examples/{UIExplorer,Movies}
Browse files Browse the repository at this point in the history
Summary:
Thanks for submitting a pull request! Please provide enough information so that others can review your pull request:

(You can skip this if you're fixing a typo or adding an app to the Showcase.)

UIExplorerActivity.java and MoviesActivity.java should override `getReactNativeHost` method. And this PR will fix #8215.

**Test plan (required)**

Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI.

Make sure tests pass on both Travis and Circle CI.

**Code formatting**

Look around. Match the style of the rest of the codebase. See also the simple [style guide](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#style-guide).

For more info, see the ["Pull Requests" section of our "Contributing" guidelines](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests).
Closes #8223

Differential Revision: D3456957

fbshipit-source-id: cc0b51e5bfaec71d210bfba81b1f7cd06a723d8c
  • Loading branch information
leeight authored and Facebook Github Bot 7 committed Jun 20, 2016
1 parent cfa9d5e commit dcc2abc
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 107 deletions.
1 change: 1 addition & 0 deletions Examples/Movies/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:targetSdkVersion="22" />

<application
android:name=".MoviesApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/rotten_tomatoes_icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,10 @@
package com.facebook.react.movies;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Nullable;

public class MoviesActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
return "MoviesApp";
}

@Override
protected @Nullable String getBundleAssetName() {
return "MoviesApp.android.bundle";
};

@Override
protected String getJSMainModuleName() {
return "Examples/Movies/MoviesApp.android";
}

@Override
protected boolean getUseDeveloperSupport() {
return true;
}

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.facebook.react.movies;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Nullable;

public class MoviesApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public String getJSMainModuleName() {
return "Examples/Movies/MoviesApp.android";
}

@Override
public @Nullable String getBundleAssetName() {
return "MoviesApp.android.bundle";
}

@Override
protected boolean getUseDeveloperSupport() {
return true;
}

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage()
);
}
};

@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:targetSdkVersion="23" />

<application
android:name=".UIExplorerApplication"
android:allowBackup="true"
android:icon="@drawable/launcher_icon"
android:label="@string/app_name"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.facebook.react.uiapp;

import android.os.Bundle;

import com.facebook.react.ReactActivity;

public class UIExplorerActivity extends ReactActivity {
private final String PARAM_ROUTE = "route";
private Bundle mInitialProps = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
// Get remote param before calling super which uses it
Bundle bundle = getIntent().getExtras();
if (bundle != null && bundle.containsKey(PARAM_ROUTE)) {
String routeUri = new StringBuilder("rnuiexplorer://example/")
.append(bundle.getString(PARAM_ROUTE))
.append("Example")
.toString();
mInitialProps = new Bundle();
mInitialProps.putString("exampleFromAppetizeParams", routeUri);
}
super.onCreate(savedInstanceState);
}

@Override
protected Bundle getLaunchOptions() {
return mInitialProps;
}

@Override
protected String getMainComponentName() {
return "UIExplorerApp";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.facebook.react.uiapp;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Nullable;

public class UIExplorerApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public String getJSMainModuleName() {
return "Examples/UIExplorer/UIExplorerApp.android";
}

@Override
public @Nullable String getBundleAssetName() {
return "UIExplorerApp.android.bundle";
}

@Override
public boolean getUseDeveloperSupport() {
return true;
}

@Override
public List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage()
);
}
};

@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
};

6 comments on commit dcc2abc

@foghina
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leeight thanks for fixing this!

@jiachaosun
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good demo.

@agrcrobles
Copy link
Contributor

@agrcrobles agrcrobles commented on dcc2abc Aug 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is great thanks, just wondering how to do it in cases like CodePush or OrientationPackage etc they receive an instance of the activity.

    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new OrientationPackage(this),
        );
    }

So I think there is no way to get Activity instance ( this ) in MainApplication so need to wait to client package to be updated and support this version.

@leeight
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agrcrobles How about Application.getCurrentActivity()

@kietcroco
Copy link

@kietcroco kietcroco commented on dcc2abc Aug 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new BluetoothIOPackage(this), //<- How pass the activity
                                        // from ReactApplication ?
          new VectorIconsPackage()
      );
    }

@Mentioum
Copy link

@Mentioum Mentioum commented on dcc2abc Aug 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kietcroco @agrcrobles

  @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new VectorIconsPackage(),
          new CodePush("***************", MainApplication.this, BuildConfig.DEBUG)
      );
    }

Is what it says on the CodePush update notes somewhere I found.

Please sign in to comment.