Code Monkey home page Code Monkey logo

react-native-custom-tabs's Introduction

React Native Custom Tabs

npm version Software License

Chrome Custom Tabs for React Native.
Custom Tabs is supported only for Android, so the behavior on each platform is bellow.

  • Android
    If Chrome is installed, open the URL in Chrome that you have customized some of the look & feel. If it is not installed, open in other browser.

  • iOS
    If Chrome is installed, open the URL in it. If it is not installed, open in Safari.

Customization and detailed behavior refer to the Usage.

Installation

npm install react-native-custom-tabs --save

To link the native module automatically, it is recommended that you use the rnpm.

rnpm link

Android

In Android, Add it in your root build.gradle(e.g. example) at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

And, provide CustomTabsPackage in your Application class.

import com.github.droibit.android.reactnative.customtabs.CustomTabsPackage;

@Override
protected List<ReactPackage> getPackages() {
    return Arrays.asList(
            ...,
            new CustomTabsPackage()
    );
}

If you use version 0.1.5 or higher, change the app build.gradle.

android {
    ...
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
}

dependencies {
    ...
    compile "com.android.support:appcompat-v7:25.0.1"
}

Usage

Open the URL as Linking of React Native.

CustomTabs.openURL('https://www.google.com').then((launched: {boolean}) => {
  console.log(`Launched custom tabs: ${launched}`);
}).catch(err => {
  console.error(err)
});

Customize for Android

You can customize the look & feel in Android. The following option is ignored in iOS.

import {
    ANIMATIONS_SLIDE,
    ANIMATIONS_FADE
} from 'react-native-custom-tabs';

CustomTabs.openURL(url, {
  toolbarColor: '#607D8B',
  enableUrlBarHiding: true,
  showPageTitle: true,
  enableDefaultShare: true,
  // Specify full animation resource identifier(package:anim/name)
  // or only resource name(in case of animation bundled with app).
  animations: {
    startEnter: 'slide_in_bottom',
    startExit: 'slide_out_bottom',
    endEnter: 'slide_in_bottom',
    endExit: 'slide_out_bottom',
  },
  // And supports SLIDE and FADE as default animation.
  // animations: ANIMATIONS_SLIDE or ANIMATIONS_FADE.
  headers: {
    'my-custom-header': 'my custom header value'
  },
  forceCloseOnRedirection: true,
});

The option to support:

property type default description
toolbarColor string undefined the Toolbar color. Supported formats are: #RRGGBB, #AARRGGBB, etc.
enableUrlBarHiding boolean undefined Enables the url bar to hide as the user scrolls down on the page.
showPageTitle boolean undefined Sets whether the title should be shown in the custom tab.
enableDefaultShare boolean undefined Whether to add a default shared items of the menu.
animations Object undefined Sets the exit and start animations. ANIMATIONS_FADE, ANIMATIONS_SLIDE or custom object with string properties startEnter, startExit, endEnter and endExit each defining an Android animation resource ID to use for the animations, such as slide_in_right.
headers Object undefined Sets any custom headers that should be used.
forceCloseOnRedirection boolean undefined Workaround that Custom Tabs doesn't close on redirecting back to app scheme.(#11)

undefined property is default behavior of the Custom Tabs.

Customize and default look & feel.
screenshot

License

Copyright (C) 2015 The Android Open Source Project
Copyright (C) 2016 Shinya Kumagai

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

react-native-custom-tabs's People

Contributors

droibit avatar manask88 avatar mikkodigia avatar nikolaik avatar patlux avatar philnova avatar wenterline-godaddy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-custom-tabs's Issues

upgrade reac-native to 0.71.6,an error occurred

A problem occurred evaluating project ':react-native-custom-tabs'.

Could not find method compile() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Execution failed for task ':react-native-custom-tabs:transformDexArchiveWithExternalLibsDexMergerForDebugAndroidTest'.

Hi Team,

I am not able to generate ./gradlew assembleAndroidTest -DtestBuildType=debug && cd ..

Error :

What went wrong:

Execution failed for task ':react-native-custom-tabs:transformDexArchiveWithExternalLibsDexMergerForDebugAndroidTest'.

java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

app/build.gradle

androidTestImplementation(project(path: ":detox"))
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test:rules:1.0.1'
ext {
    supportLibVersion = "27.0.2"
    playServicesVersion = "11.8.0"
    reactNativeVersion = "0.53.3"
}

 multiDexEnabled true

android/build.gradle:

ext {
    compileSdkVersion = 27
    buildToolsVersion = "27.0.2"
    targetSDKVersion = 27
    minSDKVersion = 21
}

android {
compileSdkVersion 25
buildToolsVersion "25.0.1"

react-native-custome-tabs/build.gradle:

    defaultConfig {
          minSdkVersion 16
          targetSdkVersion 23
          versionCode 1
          versionName "1.0"
      }
  }
  dependencies {
      compile "com.facebook.react:react-native:+"  
      compile 'com.android.support:customtabs:25.0.1'
      compile ('com.github.droibit.customtabslauncher:launcher:1.0.8') {
      exclude module: 'customtabs'
      }
      testCompile 'junit:junit:4.12'
      }

Following is the stack post https://stackoverflow.com/questions/51406881/execution-failed-for-task-react-native-custom-tabstransformdexarchivewithexte/51407576?noredirect=1#comment89827467_51407576

Close browser programmatically

Nice library!

We are using your library on Android for 0Auth login with different providers. When the user is authenticated we want to programmatically close the chrome tabview within our app.

Is this currently possible?

React custom tabs component crashing Xcode

Hello, I'm using this component to display a WebGL page on an Android phone, which works well.

However, Xcode crashes on startup and I get an "Xcode quit unexpectedly" message, every time I open my iOS project.

Path or configuration is wrong when compiling project to ios

react-native-custom-tabs/ios/ReactNativeCustomTabs/DBChromeManager.m:12:
../../react-native/React/Base/RCTUtils.h:14:9: fatal error: 'React/RCTAssert.h' file not found
#import <React/RCTAssert.h>
^~~~~~~~~~~~~~~~~~~
1 error generated.

My config

System:
OS: macOS 10.15.1
CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
Memory: 578.36 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
npm: 6.13.2 - ~/.nvm/versions/node/v12.13.1/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5977832
Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild
npmPackages:
react: 16.12.0 => 16.12.0
react-native: 0.61.5 => 0.61.5

No resource found that matches the given name: attr 'android:keyboardNavigationCluster'

Error when generating a release build:

:react-native-custom-tabs:verifyReleaseResources/Users/cameronbates/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.1.0.aar/d966a29d4964b9817b018d8a3a1d16a4/res/values-v26/values-v26.xml:13:5-16:13: AAPT: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'

build.gradle needs to be updated so builds on RN56 work. It looks like PR #33 fixes this issue

Build failing on `import android.support.customtabs.CustomTabsIntent`

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-custom-tabs/android/src/main/java/com/github/droibit/android/reactnative/customtabs/CustomTabsModule.java b/node_modules/react-native-custom-tabs/android/src/main/java/com/github/droibit/android/reactnative/customtabs/CustomTabsModule.java
index 29a0fe6..f66b403 100644
--- a/node_modules/react-native-custom-tabs/android/src/main/java/com/github/droibit/android/reactnative/customtabs/CustomTabsModule.java
+++ b/node_modules/react-native-custom-tabs/android/src/main/java/com/github/droibit/android/reactnative/customtabs/CustomTabsModule.java
@@ -5,7 +5,7 @@ import android.content.Context;
 import android.graphics.Color;
 import android.os.Bundle;
 import android.provider.Browser;
-import android.support.customtabs.CustomTabsIntent;
+import androidx.browser.customtabs.CustomTabsIntent;
 import android.text.TextUtils;
 
 import com.droibit.android.customtabs.launcher.CustomTabsLauncher;

This issue body was partially generated by patch-package.

Cannot find symbol CustomTabsIntent

Hello,

I have been struggling with a bug. I found a solution, but I am not sure why it works.

When I would run ./gradlew bundleRelease, I would get an error:

TabsModule.java:9: error: cannot find symbol import android.support.customtabs.CustomTabsIntent;

My android/gradle.properties looked like:

`android.useAndroidX=true

android.enableJetifier=true

MYAPP_UPLOAD_STORE_FILE={{keystore_here}}

MYAPP_UPLOAD_KEY_ALIAS={{alias_here}}

MYAPP_UPLOAD_STORE_PASSWORD={{password_here}}

MYAPP_UPLOAD_KEY_PASSWORD={{password_here}}

org.gradle.jvmargs=-XX:MaxHeapSize=512m -Xmx512m`

The solution was to open /node_modules/react-native-custom-tabs/android/src/main/java/com/github/droibit/android/reactnative/customtabs/CustomTabsModule.java and delete the line:

import android.support.customtabs.CustomTabsIntent;

and replace it with:

import androidx.browser.customtabs.CustomTabsIntent;

I got the idea looking at the Android documentation page for CustomTabsIntent, which notes that it is deprecated in favor of AndroidX. This is the documentation page for the AndroidX custom tabs package I used.

My questions:

  1. Why does this fix work?
  2. Is this repo still maintained? If so, would you all like a PR for this fix? I ask because I don't know if this fix is a good idea (I don't know why it works!)

Image selection from the custom tab redirects to the app

Hey guys,
basically I have an app that opens react-native-custom-tabs for the user to edit his profile. In there I have edit image that allows for the user to upload an image either by selecting one from the gallery or taking new photo. If he takes new photo and presses OK to confirm it, the user gets redirected to the app and not the previously opened custom tabs. However, if he selects an image directly from the gallery, without taking new one, he gets redirected to the custom tabs with the open edit profile page, which is the behavior I am after.

Any opinions on how this could be achieved is welcomed. Thanks.

Add a PodSpec

In a project using cocoapods, it would make more sense to include a .podspec file to this repo so we can include as a Pod.

error: cannot find symbol new CustomTabsPackage()

:app:prepareComGoogleFirebaseFirebaseCore1601Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseIid1620Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseIidInterop1600Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseMeasurementConnector1600Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseMeasurementConnectorImpl1601Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseMessaging1710Library UP-TO-DATE
:app:prepareKoenigReactNativeFcmUnspecifiedLibrary UP-TO-DATE
:app:prepareKoenigReactNativeNetworkInfoUnspecifiedLibrary UP-TO-DATE
:app:prepareKoenigReactNativeVectorIconsUnspecifiedLibrary UP-TO-DATE
:app:prepareMeLeolinShortcutBadger1117Library UP-TO-DATE
:app:prepareOrgWebkitAndroidJscR174650Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
Parsing json file: D:\on_working_project\ko_stu_repo\koenig-student\android\app\google-services.json
:app:generateDebugResources
:app:mergeDebugResources UP-TO-DATE
:app:bundleDebugJsAndAssets SKIPPED
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
D:\on_working_project\ko_stu_repo\koenig-student\android\app\src\main\java\com\koenig\MainApplication.java:29: error: cannot find symbol
           new CustomTabsPackage(),
               ^
  symbol: class CustomTabsPackage
1 error
:app:compileDebugJavaWithJavac FAILED

compilation fails with above messages

i use
"react-native": "^0.50.3",
"react-native-chrome-custom-tabs": "0.0.2",

Support custom screen transitions

It is nice that the package supports a couple of default transitions to the custom tab on Android, but in an application we're developing we'd want a custom transition when opening and closing the custom tab. Since we are using the SFSafariViewController on iOS, we'd like the Android transition to be similar, so that we can design the other UI around that.

One option to do this would of course be to add more default animations to the package, but in the long term it's probably more beneficial to support totally custom animations as well. This could be implemented by passing the identifier to an Android animation resource in the configuration. I'll post a PR soon.

Detecting the custom tab close event

Would be nice to be able to determine when the custom tab is closed, so that the application would be able to update itself to possible actions taken within the chrome tab. So would be nice if one could pass an callback argument, or register an eventlistener for when the user closes the custom tab.

Not sure if there already are some nice ways of tracking the foreground activity in react native on Android. If there are, then that would of course also be ok.

For reference react-native-safari-view has an onDismiss event

React Native 0.56+ android build failure

New version of react native have increased the targetSdkVersion. This needs to be increased in the gradle file otherwise production builds won't work on newer react native projects.

Still maintained?

Hello,

I'm wondering if this is still maintained. Any plans on bringing it back to life with up-to-date RN and dependencies?

Dismiss custom tabs

I am not sure, but I guess there is no way to dismiss custom tabs, right? I just want dismiss it programmatically from RN.

Please help, "openURL" function undefined

Hi,
I'm trying to test the functionality of this library, so I put CustomTabs.openUrl('https://www.google.com) like from the example in the readme inside of the ComponentWillMount function for one of my components. The app is giving the error "undefined is not a function "CustomTabs.openUrl...".

Details:
I am importing the library like so: var CustomTabs = require( 'react-native-custom-tabs');

Could not find com.github.droibit.customtabslauncher:launcher:1.0.8

After I install and setup react-native-custom-tabs as described, I cannot build project and receive this error:

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':react-native-custom-tabs:debugCompileClasspath'.
> Could not find com.github.droibit.customtabslauncher:launcher:1.0.8.
  Searched in the following locations:
      https://jcenter.bintray.com/com/github/droibit/customtabslauncher/launcher/1.0.8/launcher-1.0.8.pom
      https://jcenter.bintray.com/com/github/droibit/customtabslauncher/launcher/1.0.8/launcher-1.0.8.jar
  Required by:
      project :react-native-custom-tabs

To fix this issue I need to open ./node_modules/react-native-custom-tabs/android/build.gradle (which I obviously should not do) And add

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

This makes my project successfully compile and run.

headers

I'm try to set Cookies in headers but not work in android and ios.

Navigation is blocked

I am calling redirect on API response.
here is the URL and I'm using deep-link to check the status.
'manysolutions://home/success?order_id=12342'
chrome is blocking the navigation

function redirect(uri) { console.log('redirect'); console.log(uri); if(navigator.userAgent.match(/Android/i)) document.location=uri; else window.location.replace(uri); }

openURL fails on ios

Running version 0.1.7 from npm. Seems to work fine for me on Android, but on iOS I am getting an error message:

TypeError: null is not an object (evaluating 'ChromeManager.openURL')

CustomTab Sending Data Post

I am using CustomTabs to open a URL and also send some data using get method, it is working on android but when I run my app on iOS it through me an error about HTTP and https after I searched I fount due to iOS new Security feature we can't open URL with deep linking so I am wondering if there is any way to open chrome and send some data using post to that URL I tried this but not worked
openBrowser(){
CustomTabs.openURL(https://domain.subdomain.com/someTest, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(meta)
}).then((launched) => {
console.log(Launched custom tabs: ${launched});
}).catch(err => {
console.error(err)
});
}

Already have maven{}

I already have:

    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }

In my build.gradle. Do I replace it or have both as per your setup?

Not working in React Native 0.56

  • What went wrong:
    Could not determine the dependencies of task ':app:preDebugBuild'.

Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
Could not resolve project :react-native-custom-tabs.
Required by:
project :app
> Unable to find a matching configuration of project :react-native-custom-tabs: None of the consumable configurations have attributes.

iOS opens urls in Safari (or Chrome), leaving the app

Hi. I don't know if it's the expected behavior but Android open a url without leaving the app while iOS open it on Safari (or Chrome), leaving the app.

Is there any way to open a url in iOS without leaving the app?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.