Add fragment to interactive view

In short: I am trying to create my own module for a jet project for AndroidPay. AndroidPay integration is possible only using fragments (which are in the final button "Buy from AndroidPay"). So the algorithm is pretty simple, export the placeholder to native-native, wrap it in a component, and at some point just add the fragment to this placeholder using its id. So the code looks like this:

public class AndroidPayPlaceholderViewManager extends SimpleViewManager<FrameLayout>{ public static final String REACT_CLASS = "AndroidPayButton"; public AndroidPayPlaceholderViewManager(ReactApplicationContext context) { super(); } @Override public String getName() { return REACT_CLASS; } @Override protected FrameLayout createViewInstance(ThemedReactContext reactContext) { return (FrameLayout) LayoutInflater.from(reactContext).inflate(R.layout.android_pay_frg_placeholder, null); } } 

android_pay_placeholder.xml

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal"> <FrameLayout android:id="@+id/android_pay_placeholder" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal"> </FrameLayout> </FrameLayout> 

js component wrapper

 import {View, requireNativeComponent} from 'react-native'; import React, {Component} from 'react'; import {NativeModules, findNodeHandle} from 'react-native'; import {isAndroid} from '../utils'; let iface = { propTypes: { ...View.propTypes, // include the default view properties foo: String } }; let AndroidPayButtonNative = requireNativeComponent('NewStoreAndroidPayButton', iface); console.log('AndroidPayButtonNative: ', AndroidPayButtonNative); let AndroidPayModule = isAndroid() ? NativeModules.NewStoreAndroidPay : null; class AndroidPayButton extends Component { state = { loaded: false }; componentDidMount() { AndroidPayModule.loadFragment(); } render() { return ( <AndroidPayButtonNative {...this.props} /> ); } } export {AndroidPayButton}; 

built-in android module, which is responsible for loading the fragment

 public class AndroidPayModule extends ReactContextBaseJavaModule implements ActivityEventListener, LifecycleEventListener { .... @ReactMethod public void loadFragment(int placeholderId) { ... WalletFragment mWalletFragment = WalletFragment.newInstance(...); // add Wallet fragment to the UI getCurrentActivity().getFragmentManager().beginTransaction() .add(R.id.android_pay_placeholder, mWalletFragment) .commit(); // [END params_builder] } .... } 

So, when I add the "placeholder" view to the screen, I see it and even checked using the LayoutInspector, the ID is right:

enter image description here

And the result that I always get is an exception:

 java.lang.IllegalArgumentException: No view found for id 0x7f0d00a6 (com.qwerty.playground:id/android_pay_placeholder) for fragment WalletFragment{388fd9c #0 id=0x7f0d00a6} at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:965) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148) at android.app.BackStackRecord.run(BackStackRecord.java:793) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535) at android.app.FragmentManagerImpl$1.run(FragmentManager.java:482) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

So guys, any idea why the FragmentManager cannot just find a view that definitely exists, and maybe some of you did this fragment trick and reacted to your native language and succeeded? Any help would be appreciated! Thanks!

0
android android-fragments react-native android-fragmentmanager
source share

No one has answered this question yet.

See similar questions:

7
React Native: add snippet to mainactivity using native Android modules

or similar:

937
findViewById in fragment
823
onActivityResult not called in fragment
2
avoid fragment fragment stack until fragment transaction completes
one
Proguard creates a runtime error due to a specific third-party library
one
How to populate a custom list in a Snippet in Android?
one
Nested fragments in Android throw an IllegalStateException: no action
0
The specified child already has a parent. You must call removeView ()
0
Modified fragments of Android navigation boxes do not work
0
Unity3d android pluggin using exoplayer NoClassDefFoundError
-4
Android error while casting interface in fragment?

All Articles