ionic-team / ionic-portals-android

Other
4 stars 3 forks source link

feat: callback when bridge is created #26

Closed carlpoole closed 1 year ago

carlpoole commented 1 year ago

Creates a callback similar to iOS https://github.com/ionic-team/ionic-portals-ios/blob/0cc7e1a025958f4731fde861fd1a1cf24211c2ed/Sources/IonicPortals/PortalView.swift#L14

passes the bridge to the callback when the private load() function is finished and the bridge should be non null. Requested by Paylocity. It was possible to get the bridge before but no assurance it was not null until after load() had been called.

Will add usage examples to the docs.

Kotlin use:

val portalFragment = PortalFragment(checkoutPortal, (bridge) -> {
    val portalWebView = bridge.getWebView();
});

Java use:

Direct use:

portalFragment = new PortalFragment(checkoutPortal, (bridge) -> {
    WebView portalWebView = bridge.getWebView();
    return null;
});

Subclass:

public class ProfileFragment extends PortalFragment {

    public static ProfileFragment newInstance() {
        return new ProfileFragment(PortalManager.getPortal("profile"), (bridge) -> {
            WebView myWebView = bridge.getWebView();
            return null;
        });
    }

    public ProfileFragment() {
        super();
    }

    public ProfileFragment(Portal portal) {
        super(portal);
    }

    public ProfileFragment(@Nullable Portal portal, @NonNull Function1<? super Bridge, Unit> onBridgeAvailable) {
        super(portal, onBridgeAvailable);
    }

    @Override
    public void onViewCreated(@NotNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        setHasOptionsMenu(false);
    }
}