Skip to content

Commit 3db57a3

Browse files
authored
Merge branch 'develop' into rework/custom_tab
2 parents 83bf3e1 + 0b942ba commit 3db57a3

File tree

14 files changed

+76
-18
lines changed

14 files changed

+76
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ in case of vulnerabilities.
2222

2323
## [Unreleased]
2424

25+
## [3.7.0] - 2022-03-01
26+
27+
### Added
28+
- iOS: Add formSheetPreferredContentSize prop to allow for custom sized formSheet modals by [@ShaneMckenna23](https://github.com/ShaneMckenna23) ([#331](https://github.com/proyecto26/react-native-inappbrowser/pull/331)).
29+
2530
## [3.6.3] - 2021-07-05
2631

2732
### Fixed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ Property | Description
159159
`modalEnabled` (Boolean) | Present the **SafariViewController** modally or as push instead. [`true`/`false`]
160160
`enableBarCollapsing` (Boolean) | Determines whether the browser's tool bars will collapse or not. [`true`/`false`]
161161
`ephemeralWebSession` (Boolean) | Prevent re-use cookies of previous session (openAuth only) [`true`/`false`]
162+
`formSheetPreferredContentSize` (Object) | Custom size for iPad `formSheet` modals [`{width: 400, height: 500}`]
162163
163164
### Android Options
164165
Property | Description
@@ -176,6 +177,7 @@ Property | Description
176177
`hasBackButton` (Boolean) | Sets a back arrow instead of the default `X` icon to close the custom tab. [`true`/`false`]
177178
`browserPackage` (String) | Package name of a browser to be used to handle Custom Tabs.
178179
`showInRecents` (Boolean) | Determining whether browsed website should be shown as separate entry in Android recents/multitasking view. [`true`/`false`]
180+
`includeReferrer` (Boolean) | Determining whether to include your package name as referrer for the website to track. [`true`/`false`]
179181
180182
### Demo
181183

android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def safeExtGet(prop, fallback) {
2121
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
2222
}
2323

24-
def DEFAULT_COMPILE_SDK_VERSION = 28
25-
def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3"
24+
def DEFAULT_COMPILE_SDK_VERSION = 31
25+
def DEFAULT_BUILD_TOOLS_VERSION = "31.0.0"
2626
def DEFAULT_MIN_SDK_VERSION = 16
27-
def DEFAULT_TARGET_SDK_VERSION = 28
27+
def DEFAULT_TARGET_SDK_VERSION = 31
2828

2929
android {
3030
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
@@ -51,7 +51,7 @@ repositories {
5151
dependencies {
5252
implementation fileTree(dir: 'libs', include: ['*.jar'])
5353
implementation 'com.facebook.react:react-native:+'
54-
implementation 'org.greenrobot:eventbus:3.+'
54+
implementation 'org.greenrobot:eventbus:3.1.0'
5555
def supportLibVersion = safeExtGet('supportLibVersion', safeExtGet('supportVersion', null))
5656
def androidXVersion = safeExtGet('androidXVersion', null)
5757
if (supportLibVersion && androidXVersion == null) {

android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
<application>
88
<activity
9-
android:name=".ChromeTabsManagerActivity">
9+
android:name=".ChromeTabsManagerActivity"
10+
android:exported="false">
1011
</activity>
1112
</application>
1213
<queries>

android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class RNInAppBrowser {
5959
private static final String KEY_HAS_BACK_BUTTON = "hasBackButton";
6060
private static final String KEY_BROWSER_PACKAGE = "browserPackage";
6161
private static final String KEY_SHOW_IN_RECENTS = "showInRecents";
62+
private static final String KEY_INCLUDE_REFERRER = "includeReferrer";
6263

6364
private static final String ACTION_CUSTOM_TABS_CONNECTION = "android.support.customtabs.action.CustomTabsService";
6465
private static final String CHROME_PACKAGE_STABLE = "com.android.chrome";
@@ -201,7 +202,7 @@ public void open(Context context, final ReadableMap options, final Promise promi
201202
}
202203

203204
registerEventBus();
204-
205+
205206
intent.setData(Uri.parse(url));
206207
if (options.hasKey(KEY_SHOW_PAGE_TITLE)) {
207208
builder.setShowTitle(options.getBoolean(KEY_SHOW_PAGE_TITLE));
@@ -210,6 +211,12 @@ public void open(Context context, final ReadableMap options, final Promise promi
210211
intent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE);
211212
}
212213

214+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && options.hasKey(KEY_INCLUDE_REFERRER)
215+
&& options.getBoolean(KEY_INCLUDE_REFERRER)) {
216+
intent.putExtra(Intent.EXTRA_REFERRER,
217+
Uri.parse("android-app://" + context.getApplicationContext().getPackageName()));
218+
}
219+
213220
currentActivity.startActivity(
214221
ChromeTabsManagerActivity.createStartIntent(currentActivity, intent),
215222
customTabsIntent.startAnimationBundle);

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
android:label="@string/app_name"
1717
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
1818
android:launchMode="singleTask"
19+
android:exported="true"
1920
android:windowSoftInputMode="adjustResize">
2021
<intent-filter>
2122
<action android:name="android.intent.action.MAIN" />

example/android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
buildscript {
44
ext {
5-
buildToolsVersion = "30.0.2"
5+
buildToolsVersion = "31.0.0"
66
minSdkVersion = 21
7-
compileSdkVersion = 30
8-
targetSdkVersion = 30
7+
compileSdkVersion = 31
8+
targetSdkVersion = 31
99
ndkVersion = "21.4.7075529"
1010
androidXAnnotation = "1.2.0"
1111
androidXBrowser = "1.3.0"
@@ -15,7 +15,7 @@ buildscript {
1515
mavenCentral()
1616
}
1717
dependencies {
18-
classpath("com.android.tools.build:gradle:4.2.2")
18+
classpath("com.android.tools.build:gradle:7.0.0")
1919
// NOTE: Do not place your application dependencies here; they belong
2020
// in the individual module build.gradle files
2121
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

example/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const openLink = async (url, statusBarStyle, animated = true) => {
4343
hasBackButton: true,
4444
browserPackage: null,
4545
showInRecents: false,
46+
includeReferrer: true,
4647
});
4748
// A delay to show an alert when the browser is closed
4849
await sleep(800);

index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ declare module 'react-native-inappbrowser-reborn' {
3636
| 'partialCurl',
3737
modalEnabled?: boolean,
3838
enableBarCollapsing?: boolean,
39-
ephemeralWebSession?: boolean
39+
ephemeralWebSession?: boolean,
40+
formSheetPreferredContentSize?: { width: number, height: number },
4041
}
4142

4243
export type InAppBrowserAndroidOptions = {
@@ -58,6 +59,7 @@ declare module 'react-native-inappbrowser-reborn' {
5859
hasBackButton?: boolean,
5960
browserPackage?: string,
6061
showInRecents?: boolean
62+
includeReferrer?: boolean,
6163
}
6264

6365
export type InAppBrowserOptions = InAppBrowserAndroidOptions | InAppBrowseriOSOptions;

ios/RNInAppBrowser.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ + (BOOL)requiresMainQueueSetup
148148
NSNumber* preferredControlTintColor = [options valueForKey:@"preferredControlTintColor"];
149149
NSString* modalPresentationStyle = [options valueForKey:@"modalPresentationStyle"];
150150
NSString* modalTransitionStyle = [options valueForKey:@"modalTransitionStyle"];
151+
NSDictionary* formSheetPreferredContentSize = [options valueForKey:@"formSheetPreferredContentSize"];
151152

152153
BOOL readerMode = [options[@"readerMode"] boolValue];
153154
BOOL enableBarCollapsing = [options[@"enableBarCollapsing"] boolValue];
@@ -207,6 +208,16 @@ + (BOOL)requiresMainQueueSetup
207208
if(animated) {
208209
safariHackVC.modalTransitionStyle = [self getTransitionStyle: modalTransitionStyle];
209210
}
211+
212+
if([modalPresentationStyle isEqualToString:@"formSheet"] && formSheetPreferredContentSize){
213+
NSNumber *width = [formSheetPreferredContentSize valueForKey:@"width"];
214+
NSNumber *height = [formSheetPreferredContentSize valueForKey:@"height"];
215+
216+
if(width && height){
217+
safariHackVC.preferredContentSize = CGSizeMake([width doubleValue], [height doubleValue]);
218+
}
219+
}
220+
210221
safariHackVC.presentationController.delegate = self;
211222
#pragma clang diagnostic push
212223
#pragma clang diagnostic ignored "-Wpartial-availability"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-inappbrowser-reborn",
3-
"version": "3.6.3",
3+
"version": "3.7.0",
44
"description": "InAppBrowser for React Native",
55
"main": "index.js",
66
"scripts": {

types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type InAppBrowseriOSOptions = {|
4141
modalEnabled?: boolean,
4242
enableBarCollapsing?: boolean,
4343
ephemeralWebSession?: boolean,
44+
formSheetPreferredContentSize?: { width: number, height: number },
4445
|};
4546

4647
export type InAppBrowserAndroidOptions = {|
@@ -62,6 +63,7 @@ export type InAppBrowserAndroidOptions = {|
6263
hasBackButton?: boolean,
6364
browserPackage?: string,
6465
showInRecents?: boolean,
66+
includeReferrer?: boolean,
6567
|};
6668

6769
export type InAppBrowserOptions = {

utils.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
Linking,
1010
Platform,
1111
AppState,
12-
NativeModules
12+
NativeModules,
13+
EmitterSubscription
1314
} from 'react-native';
1415
import type {
1516
BrowserResult,
@@ -22,6 +23,7 @@ import type {
2223
export const RNInAppBrowser = NativeModules.RNInAppBrowser;
2324

2425
let _redirectHandler: ?(event: RedirectEvent) => void;
26+
let _linkingEventSubscription: ?EmitterSubscription;
2527

2628
type AppStateStatus = typeof AppState.currentState
2729

@@ -33,7 +35,10 @@ function waitForRedirectAsync(returnUrl: string): Promise<RedirectResult> {
3335
}
3436
};
3537

36-
Linking.addEventListener('url', _redirectHandler);
38+
_linkingEventSubscription = Linking.addEventListener(
39+
'url',
40+
_redirectHandler
41+
);
3742
});
3843
}
3944

@@ -46,13 +51,26 @@ function handleAppStateActiveOnce(): Promise<void> {
4651
if (AppState.currentState === 'active') {
4752
return resolve();
4853
}
54+
let appStateEventSubscription: ?EmitterSubscription;
55+
4956
function handleAppStateChange(nextAppState: AppStateStatus) {
5057
if (nextAppState === 'active') {
51-
AppState.removeEventListener('change', handleAppStateChange);
58+
if (
59+
appStateEventSubscription &&
60+
appStateEventSubscription.remove !== undefined
61+
) {
62+
appStateEventSubscription.remove();
63+
} else {
64+
AppState.removeEventListener('change', handleAppStateChange);
65+
}
5266
resolve();
5367
}
5468
}
55-
AppState.addEventListener('change', handleAppStateChange);
69+
70+
appStateEventSubscription = AppState.addEventListener(
71+
'change',
72+
handleAppStateChange
73+
);
5674
});
5775
}
5876

@@ -137,7 +155,15 @@ export async function openAuthSessionPolyfillAsync(
137155

138156
export function closeAuthSessionPolyfillAsync(): void {
139157
if (_redirectHandler) {
140-
Linking.removeEventListener('url', _redirectHandler);
158+
if (
159+
_linkingEventSubscription &&
160+
_linkingEventSubscription.remove !== undefined
161+
) {
162+
_linkingEventSubscription.remove();
163+
_linkingEventSubscription = null;
164+
} else {
165+
Linking.removeEventListener('url', _redirectHandler);
166+
}
141167
_redirectHandler = null;
142168
}
143169
}

0 commit comments

Comments
 (0)