jondot / awesome-react-native

Awesome React Native components, news, tools, and learning material!
http://www.awesome-react-native.com
34.29k stars 3.97k forks source link

None of "Open Source App" working #1056

Open peterweb2005 opened 3 years ago

peterweb2005 commented 3 years ago

as title

https://github.com/jondot/awesome-react-native#open-source-apps

it is not possible to find a worked sample react native app, even not with expo, which is more than 2 years ago

miniyarov commented 3 years ago

I recently published an open source app to App Store, I hope this helps. https://github.com/zudvpn/ZudVPN https://apps.apple.com/us/app/zudvpn-personal-vpn-on-cloud/id1517610454

johnpawl commented 3 years ago

Help !!!

I want to get back to android activity from react-native activity using backkey .

MainActivity.java

public class MainActivity extends AppCompatActivity {

Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startRNPage();
        }
    });
}

private void startRNPage() {
    Intent intent = new Intent(this, ReactNativeActivity.class);
    startActivity(intent);
    finish();
}
}

ReactNativeActivity.java

public class ReactNativeActivity extends AppCompatActivity {
private ReactRootView mReactRootView;
private ReactInstanceManager mReactInstanceManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SoLoader.init(this, false);

    mReactRootView = new ReactRootView(this);
    List<ReactPackage> packages = new PackageList(getApplication()).getPackages();
    // Packages that cannot be autolinked yet can be added manually here, for example:
    // packages.add(new MyReactNativePackage());
    // Remember to include them in `settings.gradle` and `app/build.gradle` too.

    mReactInstanceManager = ReactInstanceManager.builder()
    .setApplication(getApplication())
    .setCurrentActivity(this)
    .setBundleAssetName("index.android.bundle")
    .setJSMainModulePath("index")
    .addPackages(packages)
    .setUseDeveloperSupport(BuildConfig.DEBUG)
    .setInitialLifecycleState(LifecycleState.RESUMED)
    .build();
    // The string here (e.g. "MyReactNativeApp") has to match
    // the string in AppRegistry.registerComponent() in index.js
    mReactRootView.startReactApplication(mReactInstanceManager, "firstpro", null);

    setContentView(mReactRootView);
    }
@Override
public void onBackPressed() {
    if (mReactInstanceManager != null) {
        mReactInstanceManager.onBackPressed();
    } else {
      super.onBackPressed();
    }
}
}

I also tried the following code in ReactNativeActivity.java

public void onBackPressed() {
    if (mReactInstanceManager != null) {
        mReactInstanceManager.onBackPressed();
    } else {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }
}

If I pressed the back button it didn't get back to android activity.

How can I get back to android activity from react-native activity using backkey?