proyecto26 / react-native-inappbrowser

📱InAppBrowser for React Native (Android & iOS) 🤘
https://www.npmjs.com/package/react-native-inappbrowser-reborn
MIT License
1.31k stars 223 forks source link

Error: Can not read property isAvailable of null #328

Closed chyamuna closed 2 years ago

chyamuna commented 2 years ago

We are facing the error 'Can not read property isAvailable of null' with below simple code

import { InAppBrowser } from 'react-native-inappbrowser-reborn';
.....
  try {
    if (await InAppBrowser.isAvailable()) {
      const result = await InAppBrowser.open(url);
      Alert.alert(JSON.stringify(result));
    }
  } catch (error) {
    Alert.alert(error.message);
  }

React native version : 0.64.2 react-native-inappbrowser version : 3.6.3 using typescript Android API 30 pixel emulator

Note:

  1. it's not expo project ( we have android and ios separate folders and we don't have custom code there)
  2. We did linking ( react-native link react-native-inappbrowser && react-native run-android)
jdnichollsc commented 2 years ago

Please attach a reproducible demo to be able to debug your issue 👍

con4man commented 2 years ago

I am also seeing this error on Android physical device. It works when I install the app to the personal profile. However, when I deploy it to the AWP (Android Work Profile), this shows up. I believe Google Chrome may be disabled in our AWP since we do not see the app in our AWP play store. Could this error be related to not having the Google Chrome browser available?

image

public handleNewsPress = (index: number) => {
    const {newsFeed} = this.props;
    NativeInAppBrowser(newsFeed.data[index].Link);
};
export const NativeInAppBrowser = async (URL: string) => {
  try {
    if (await InAppBrowser.isAvailable()) {
      const result = await InAppBrowser.open(URL, {
        // iOS Properties
        dismissButtonStyle: "done",
        readerMode: false,
        animated: true,
        modalPresentationStyle: "pageSheet",
        modalTransitionStyle: "coverVertical",
        modalEnabled: true,
        enableBarCollapsing: false,
        ephemeralWebSession: true,
        // Android Properties
        showTitle: true,
        toolbarColor: "#FFFFFF",
        enableUrlBarHiding: false,
        enableDefaultShare: true,
        forceCloseOnRedirection: false,
        // Specify full animation resource identifier(package:anim/name)
        // or only resource name(in case of animation bundled with app).
        animations: {
          startEnter: "slide_in_right",
          startExit: "slide_out_left",
          endEnter: "slide_in_left",
          endExit: "slide_out_right"
        },
        headers: {
          "my-custom-header": "my custom header value"
        }
      });
    } else {
      Linking.openURL(URL);
    }
  } catch (error: any) {
    Alert.alert(error.message);
  }
}
julienR2 commented 2 years ago

Hey @chyamuna ! I just faced the same issue, and adding those missing lines from the installation doc in our build.gradle fixed the issues

androidXAnnotation = "1.2.0"
androidXBrowser = "1.3.0"

CleanShot 2022-02-11 at 17 25 23@2x

Does it solves the issue for you too ? (Weirdly enough, we have another project without those lines, but also on AndroidX, that is working fine 🙃 )

jdnichollsc commented 2 years ago

This error comes from a fail native Linking (wrong installation), Android Backward compatibility is hard to support 😅

chyamuna commented 2 years ago

Our app works on another platform. Platform is a hybrid app, where it doesn't support auto linking. I was incorrectly linking the module in our app. when I added this android native module to our platform android native modules, our app could able to consume this module and the error is not coming anymore

trongtai1801 commented 1 year ago

In my case, I added these line to android/build.grade, run cd android && ./gradlew clean && cd .. and rebuild

image