Skip to content

Commit

Permalink
Merge pull request #76 from proyecto26/develop
Browse files Browse the repository at this point in the history
Release 3.1.0
  • Loading branch information
jdnichollsc authored Jun 27, 2021
2 parents 25bba0d + b951c81 commit 432d346
Show file tree
Hide file tree
Showing 14 changed files with 8,499 additions and 197 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ in case of vulnerabilities.

## [Unreleased]

## [3.1.0] - 2021-06-27

### Added
- Add `navigationBarColor` and `navigationBarDividerColor` options by [@jdnichollsc](https://github.com/jdnichollsc).
- Add try catch block to `Safari View Controller` and `ChromeTabs` to validate the url.

### Fixed
- Fix invalid scheme with iOS 14.5.
- Fix `openAuth` crashed when going to be closed and then press the cancel button.

## [3.0.2] - 2020-02-01
### Fixed
- Fix wrong param passed to parseColor method by [@ronalson](https://github.com/ronalson) ([#56](https://github.com/proyecto26/nativescript-inappbrowser/pull/56)).
Expand Down Expand Up @@ -87,7 +97,8 @@ in case of vulnerabilities.
- Methods to open and close external urls to authenticate the user **(openAuth, closeAuth)** using deep linking.
- `isAvailable` method to detect if the device supports the plugin.

[Unreleased]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v3.0.2...HEAD
[Unreleased]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v3.1.0...HEAD
[3.1.0]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v3.0.2...v3.1.0
[3.0.2]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v3.0.1...v3.0.2
[3.0.1]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v3.0.0...v3.0.1
[3.0.0]: https://github.com/proyecto26/nativescript-inappbrowser/compare/v2.3.0...v3.0.0
Expand Down
75 changes: 67 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,52 @@
<img width="400px" src="https://github.com/proyecto26/nativescript-inappbrowser/blob/develop/img/inappbrowser.png?raw=true">
</p>

## Who is using InAppBrowser?

Do you want to see this package in action? Check these awesome projects, yay! 🎉
- [Oxycar](https://oxycar.com) - Offers innovative ways to facilitate home-work journeys.
- [Pegus Digital](https://pegus.digital/) - Your innovation partner in digital product development.

Share your awesome project [here](hhttps://github.com/proyecto26/nativescript-inappbrowser/issues/49)! ❤️

## Getting started

```javascript
tns plugin add nativescript-inappbrowser
```

### Manual installation

- **Android Platform with Android Support:**

Modify your **android/build.gradle** configuration:
```
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
// Only using Android Support libraries
supportLibVersion = "28.0.0"
}
```

- **Android Platform with AndroidX:**

Modify your **android/build.gradle** configuration:
```
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
// Remove 'supportLibVersion' property and put specific versions for AndroidX libraries
androidXBrowser = "1.0.0"
// Put here other AndroidX dependencies
}
```

## Usage

Expand Down Expand Up @@ -75,6 +114,8 @@ Property | Description
`showTitle` (Boolean) | Sets whether the title should be shown in the custom tab. [`true`/`false`]
`toolbarColor` (String) | Sets the toolbar color. [`gray`/`#808080`]
`secondaryToolbarColor` (String) | Sets the color of the secondary toolbar. [`white`/`#FFFFFF`]
`navigationBarColor` (String) | Sets the navigation bar color. [`gray`/`#808080`]
`navigationBarDividerColor` (String) | Sets the navigation bar divider color. [`white`/`#FFFFFF`]
`enableUrlBarHiding` (Boolean) | Enables the url bar to hide as the user scrolls down on the page. [`true`/`false`]
`enableDefaultShare` (Boolean) | Adds a default share item to the menu. [`true`/`false`]
`animations` (Object) | Sets the start and exit animations. [`{ startEnter, startExit, endEnter, endExit }`]
Expand All @@ -93,7 +134,7 @@ import { InAppBrowser } from 'nativescript-inappbrowser';
...
openLink = async () => {
try {
const url = 'https://www.google.com'
const url = 'https://www.proyecto26.com'
if (await InAppBrowser.isAvailable()) {
const result = await InAppBrowser.open(url, {
// iOS Properties
Expand All @@ -110,6 +151,8 @@ import { InAppBrowser } from 'nativescript-inappbrowser';
showTitle: true,
toolbarColor: '#6200EE',
secondaryToolbarColor: 'black',
navigationBarColor: 'black',
navigationBarDividerColor: 'white',
enableUrlBarHiding: true,
enableDefaultShare: true,
forceCloseOnRedirection: false,
Expand Down Expand Up @@ -156,12 +199,16 @@ define your app scheme and replace `my-scheme` and `my-host` with your info.

- Enable deep linking (Android) - **[AndroidManifest.xml](https://github.com/proyecto26/nativescript-inappbrowser/blob/master/demo/app/App_Resources/Android/src/main/AndroidManifest.xml#L41)**
```
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="my-scheme" android:host="my-host" />
</intent-filter>
<activity
...
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="my-scheme" android:host="my-host" android:pathPrefix="" />
</intent-filter>
</activity>
```

- Enable deep linking (iOS) - **[Info.plist](https://github.com/proyecto26/nativescript-inappbrowser/blob/master/demo/app/App_Resources/iOS/Info.plist#L21)**
Expand Down Expand Up @@ -217,13 +264,17 @@ import { getDeepLink } from './utilities';
}
})
} else Utils.openUrl(url)
} catch (error) {
} catch {
Utils.openUrl(url)
}
}
...
```

### StatusBar

The StatusBar will keep the last one provided in your app. So if the StatusBar is `dark-content` before you open the browser this will keep it.

### Authentication

Using in-app browser tabs (like SFAuthenticationSession/ASWebAuthenticationSession and Android Custom Tabs) where available. Embedded user-agents, known as web-views (like UIWebView and WKWebView), are explicitly not supported due to the usability and security reasons documented in [Section 8.12 of RFC 8252](https://tools.ietf.org/html/rfc8252#section-8.12).
Expand Down Expand Up @@ -278,6 +329,14 @@ Support this project with your organization. Your logo will show up here with a
I believe in Unicorns 🦄
Support [me](http://www.paypal.me/jdnichollsc/2), if you do too.

Donate **Ethereum**, **ADA**, **BNB**, **SHIBA**, **USDT**, **DOGE**:

![Wallet address](https://user-images.githubusercontent.com/2154886/123501719-84bf1900-d60c-11eb-882c-98a499cea323.png)

> Wallet address: 0x3F9fA8021B43ACe578C2352861Cf335449F33427
Please let us know your contributions! 🙏

## Enterprise 💼

Available as part of the Tidelift Subscription.
Expand Down
7 changes: 7 additions & 0 deletions demo/app/App_Resources/iOS/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
end
end
end
4 changes: 3 additions & 1 deletion demo/app/App_Resources/iOS/build.xcconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// You can add custom settings here
// for example you can uncomment the following line to force distribution code signing
// CODE_SIGN_IDENTITY = iPhone Distribution
// CODE_SIGN_IDENTITY = iPhone Distribution
// To build for device with XCode you need to specify your development team.
// DEVELOPMENT_TEAM = YOUR_TEAM_ID;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;

VALIDATE_WORKSPACE = YES;
4 changes: 3 additions & 1 deletion demo/app/home/home-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class HelloWorldModel extends Observable {
super();

// Initialize default values.
this._url = 'https://www.google.com';
this._url = 'https://nativescript.org';
}

get url(): string {
Expand Down Expand Up @@ -42,6 +42,8 @@ export class HelloWorldModel extends Observable {
showTitle: true,
toolbarColor: '#6200EE',
secondaryToolbarColor: 'black',
navigationBarColor: 'black',
navigationBarDividerColor: 'white',
enableUrlBarHiding: true,
enableDefaultShare: true,
forceCloseOnRedirection: true,
Expand Down
62 changes: 38 additions & 24 deletions src/ChromeTabsManagerActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import Bundle = android.os.Bundle;
import { Observable } from '@nativescript/core';
import { BROWSER_TYPES } from './InAppBrowser.common';
import { DISMISSED_EVENT } from './utils.android';
import { log } from './utils.common';


export class ChromeTabsEvent extends Observable {
public message: String;
public resultType: String;
public message: string;
public resultType: string;
public isError: boolean
}

export const BROWSER_ACTIVITY_EVENTS = new ChromeTabsEvent();
Expand All @@ -18,6 +20,16 @@ const KEY_BROWSER_INTENT = 'browserIntent';
const BROWSER_RESULT_TYPE = 'browserResultType';
const DEFAULT_RESULT_TYPE = BROWSER_TYPES.DISMISS;

const notifyMessage = (message: string, resultType: BROWSER_TYPES, isError = false) => {
BROWSER_ACTIVITY_EVENTS.set('message', message);
BROWSER_ACTIVITY_EVENTS.set('resultType', resultType);
BROWSER_ACTIVITY_EVENTS.set('isError', isError);
BROWSER_ACTIVITY_EVENTS.notify({
eventName: DISMISSED_EVENT,
object: BROWSER_ACTIVITY_EVENTS
});
};

/**
* Manages the custom chrome tabs intent by detecting when it is dismissed by the user and allowing
* to close it programmatically when needed.
Expand All @@ -27,28 +39,36 @@ const DEFAULT_RESULT_TYPE = BROWSER_TYPES.DISMISS;
export class ChromeTabsManagerActivity extends android.app.Activity {
private mOpened = false;
private resultType = null;
private isError = false;

constructor() {
super();
return global.__native(this);
}

public onCreate(savedInstanceState?: Bundle): void {
super.onCreate(savedInstanceState);

// This activity gets opened in 2 different ways. If the extra KEY_BROWSER_INTENT is present we
// start that intent and if it is not it means this activity was started with FLAG_ACTIVITY_CLEAR_TOP
// in order to close the intent that was started previously so we just close this.
if (
this.getIntent().hasExtra(KEY_BROWSER_INTENT)
&& (!savedInstanceState || !savedInstanceState.getString(BROWSER_RESULT_TYPE))
) {
const browserIntent = <Intent>this.getIntent().getParcelableExtra(KEY_BROWSER_INTENT);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
this.startActivity(browserIntent);
this.resultType = DEFAULT_RESULT_TYPE;
} else {
try {
super.onCreate(savedInstanceState);

// This activity gets opened in 2 different ways. If the extra KEY_BROWSER_INTENT is present we
// start that intent and if it is not it means this activity was started with FLAG_ACTIVITY_CLEAR_TOP
// in order to close the intent that was started previously so we just close this.
if (
this.getIntent().hasExtra(KEY_BROWSER_INTENT)
&& (!savedInstanceState || !savedInstanceState.getString(BROWSER_RESULT_TYPE))
) {
const browserIntent = <Intent>this.getIntent().getParcelableExtra(KEY_BROWSER_INTENT);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
this.startActivity(browserIntent);
this.resultType = DEFAULT_RESULT_TYPE;
} else {
this.finish();
}
} catch (error) {
this.isError = true;
notifyMessage('Unable to open url.', this.resultType, this.isError);
this.finish();
log(`InAppBrowser: ${error}`);
}
}

Expand All @@ -70,18 +90,12 @@ export class ChromeTabsManagerActivity extends android.app.Activity {
if (this.resultType) {
switch (this.resultType) {
case BROWSER_TYPES.CANCEL:
BROWSER_ACTIVITY_EVENTS.set('message', 'chrome tabs activity closed');
BROWSER_ACTIVITY_EVENTS.set('resultType', this.resultType);
notifyMessage('chrome tabs activity closed', this.resultType, this.isError);
break;
default:
BROWSER_ACTIVITY_EVENTS.set('message', 'chrome tabs activity destroyed');
BROWSER_ACTIVITY_EVENTS.set('resultType', DEFAULT_RESULT_TYPE);
notifyMessage('chrome tabs activity destroyed', DEFAULT_RESULT_TYPE, this.isError);
break;
}
BROWSER_ACTIVITY_EVENTS.notify({
eventName: DISMISSED_EVENT,
object: BROWSER_ACTIVITY_EVENTS
});
this.resultType = null;
}
super.onDestroy();
Expand Down
Loading

0 comments on commit 432d346

Please sign in to comment.