swan-io / react-native-browser

An easy-to-use in-app browser module for React Native, powered by Chrome Custom Tabs / SFSafariViewController.
MIT License
135 stars 11 forks source link

It does not open for android version 11 #15

Closed HammadIqbal-1 closed 2 weeks ago

HammadIqbal-1 commented 2 weeks ago

Before submitting a new issue

Bug summary

there is no error everything works fine but it does not open the in-app browser

Library version

"@swan-io/react-native-browser": "^0.3.1",

Environment info

"react-native": "0.69",

    "@swan-io/react-native-browser": "^0.3.1",

Steps to reproduce

install the package in any device with api below 14 it will not open without any error

Reproducible sample code

import React from 'react';
import {
  View,
  ScrollView,
  TouchableOpacity,
  StyleSheet,
  Button as RNButton,
  Dimensions,
} from 'react-native';
import {Text} from 'react-native-paper';
import {openBrowser} from '@swan-io/react-native-browser';

const styles = StyleSheet.create({
  cardStyle: {
    padding: 5,
    borderRadius: 0,
    backgroundColor: '#F5F5F5',
    width: Dimensions.get('window').width * 0.94,
    overflow: 'hidden',
    marginBottom: 30,
  },
  titleStyle: {
    color: '#2C3539',
    fontWeight: 'bold',
    fontSize: 24,
    textAlign: 'center',
    marginVertical: 10,
  },
  infoText: {
    color: '#2C3539',
    fontSize: 15,
    textAlign: 'left',
    marginBottom: 20,
    paddingHorizontal: 10,
    lineHeight: 26,
  },
  linkContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    paddingVertical: 8,
    paddingHorizontal: 10,
    backgroundColor: '#E8F5F1',
    borderRadius: 10,
    marginVertical: 5,
  },
  bullet: {
    fontSize: 18,
    color: '#000',
    marginRight: 10,
  },
  linkItemText: {
    color: '#0BDDB4',
    fontSize: 16,
    flexShrink: 1,
  },
});

const DidYouKnow = ({route}) => {
  const {data} = route.params;

  const handleLinkPress = async url => {
    try {
      console.log('we opeined');
      await openBrowser(url, {
        dismissButtonStyle: 'cancel',
        preferredBarTintColor: '#453AA4',
        preferredControlTintColor: 'white',
      });
      console.log('we out opened');
    } catch (error) {
      console.error('Error opening browser:', error);
    }
  };

  return (
    <ScrollView
      contentContainerStyle={{padding: 10, backgroundColor: '#F5F5F5'}}>
      <View style={styles.cardStyle}>
        <Text style={styles.titleStyle}>{data.title}</Text>
        <Text style={styles.infoText}>{data.content}</Text>
        {data.links?.split(',').map((link, idx) => (
          <TouchableOpacity
            key={idx}
            onPress={() => handleLinkPress(link.trim())}
            style={styles.linkContainer}>
            <Text style={styles.bullet}>•</Text>
            <Text style={styles.linkItemText}>{link.trim()}</Text>
          </TouchableOpacity>
        ))}
      </View>
    </ScrollView>
  );
};

export default DidYouKnow;
zoontek commented 2 weeks ago

@HammadIqbal-1 It works great on Android 6+.

Are you sure this isn't related to this? You have to accept Chrome terms and conditions first, and developer using emulators tends to forget this step.

zoontek commented 2 weeks ago

I added a warning regarding this in the README