Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jdnichollsc committed Sep 7, 2018
1 parent bf51cfd commit 0e6372a
Show file tree
Hide file tree
Showing 72 changed files with 24,786 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": ["react-native"],
"plugins": [
[
"module-resolver"
],
"transform-decorators-legacy",
"transform-exponentiation-operator",
"transform-export-extensions"
]
}
46 changes: 46 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[ignore]

# We fork some components by platform.
.*/*.web.js
.*/*.android.js

# Some modules have their own node_modules with overlap
.*/node_modules/node-haste/.*

# Ignore react-tools where there are overlaps, but don't ignore anything that
# react-native relies on
.*/node_modules/react-tools/src/React.js
.*/node_modules/react-tools/src/renderers/shared/event/EventPropagators.js
.*/node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderEventPlugin.js
.*/node_modules/react-tools/src/shared/vendor/core/ExecutionEnvironment.js


# Ignore commoner tests
.*/node_modules/commoner/test/.*

# See https://github.com/facebook/flow/issues/442
.*/react-tools/node_modules/commoner/lib/reader.js

# Ignore jest
.*/react-native/node_modules/jest-cli/.*

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js

[options]
module.system=haste

munge_underscores=true

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FixMe

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(1[0-4]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(1[0-4]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy

[version]
0.14.0
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -text
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

# OSX
#
.DS_Store

# node.js
#
node_modules/
npm-debug.log
yarn-error.log


# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace


# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# BUCK
buck-out/
\.buckd/
*.keystore

43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@

# react-native-inappbrowser
InAppBrowser for React Native

## Getting started

`$ npm install react-native-inappbrowser --save`

### Mostly automatic installation

`$ react-native link react-native-inappbrowser`

### Manual installation


#### iOS

1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
2. Go to `node_modules``react-native-inappbrowser` and add `RNInAppBrowser.xcodeproj`
3. In XCode, in the project navigator, select your project. Add `libRNInAppBrowser.a` to your project's `Build Phases``Link Binary With Libraries`
4. Run your project (`Cmd+R`)<

#### Android

1. Open up `android/app/src/main/java/[...]/MainActivity.java`
- Add `import com.proyecto26.inappbrowser.RNInAppBrowserPackage;` to the imports at the top of the file
- Add `new RNInAppBrowserPackage()` to the list returned by the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```
include ':react-native-inappbrowser'
project(':react-native-inappbrowser').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-inappbrowser/android')
```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```
compile project(':react-native-inappbrowser')
```

## Usage
```javascript
import RNInAppBrowser from 'react-native-inappbrowser';

// TODO: What to do with the module?
RNInAppBrowser;
```

47 changes: 47 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'


buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
mavenCentral()
maven { url "https://maven.google.com" }
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}

repositories {
mavenCentral()
}

dependencies {
api fileTree(dir: "libs", include: ["*.jar"])
api 'com.android.support:multidex:1.0.1'
api 'com.android.support:support-annotations'
api "com.facebook.react:react-native:+"
api 'com.android.support:customtabs:27.1.1'
api 'de.greenrobot:eventbus:2.4.0'
}

5 changes: 5 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.proyecto26.inappbrowser">
</manifest>

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2015-present 650 Industries. All rights reserved.

package com.proyecto26.inappbrowser;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;

import de.greenrobot.event.EventBus;

/**
* Manages the custom chrome tabs intent by detecting when it is dismissed by the user and allowing
* to close it programmatically when needed.
*/
public class ChromeTabsManagerActivity extends Activity {

public static class ChromeTabsDismissedEvent {}

static final String KEY_BROWSER_INTENT = "browserIntent";

private boolean mOpened = false;

public static Intent createStartIntent(Context context, Intent authIntent) {
Intent intent = createBaseIntent(context);
intent.putExtra(KEY_BROWSER_INTENT, authIntent);
return intent;
}

public static Intent createDismissIntent(Context context) {
Intent intent = createBaseIntent(context);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return intent;
}

private static Intent createBaseIntent(Context context) {
return new Intent(context, ChromeTabsManagerActivity.class);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
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 (getIntent().hasExtra(KEY_BROWSER_INTENT)) {
Intent browserIntent = getIntent().getParcelableExtra(KEY_BROWSER_INTENT);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(browserIntent);
} else {
finish();
}
}

@Override
protected void onResume() {
super.onResume();

// onResume will get called twice, the first time when the activity is created and a second
// time if the user closes the chrome tabs activity. Knowing this we can detect if the user
// dismissed the activity and send an event accordingly.
if (!mOpened) {
mOpened = true;
} else {
EventBus.getDefault().post(new ChromeTabsDismissedEvent());
finish();
}
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

package com.proyecto26.inappbrowser;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.Nullable;
import android.support.customtabs.CustomTabsIntent;

import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;

import de.greenrobot.event.EventBus;

public class RNInAppBrowserModule extends ReactContextBaseJavaModule {
private final static String ERROR_CODE = "InAppBrowser";
private final ReactApplicationContext reactContext;

private @Nullable Promise mOpenBrowserPromise;

public RNInAppBrowserModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}

@Override
public String getName() {
return "RNInAppBrowser";
}

@ReactMethod
public void open(final String url, final Promise promise) {
if (mOpenBrowserPromise != null) {
WritableMap result = Arguments.createMap();
result.putString("type", "cancel");
mOpenBrowserPromise.resolve(result);
return;
}
mOpenBrowserPromise = promise;

final Activity activity = getCurrentActivity();
if (activity == null) {
promise.reject(ERROR_CODE, "No activity");
mOpenBrowserPromise = null;
return;
}

CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();

Intent intent = customTabsIntent.intent;
intent.setData(Uri.parse(url));
intent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE);

EventBus.getDefault().register(this);

activity.startActivity(
ChromeTabsManagerActivity.createStartIntent(activity, intent));
}

@ReactMethod
public void close() {
if (mOpenBrowserPromise == null) {
return;
}

final Activity activity = getCurrentActivity();
if (activity == null) {
mOpenBrowserPromise.reject(ERROR_CODE, "No activity");
mOpenBrowserPromise = null;
return;
}

EventBus.getDefault().unregister(this);

WritableMap result = Arguments.createMap();
result.putString("type", "dismiss");
mOpenBrowserPromise.resolve(result);
mOpenBrowserPromise = null;

activity.startActivity(
ChromeTabsManagerActivity.createDismissIntent(activity));
}

public void onEvent(ChromeTabsManagerActivity.ChromeTabsDismissedEvent event) {
EventBus.getDefault().unregister(this);

Assertions.assertNotNull(mOpenBrowserPromise);

WritableMap result = Arguments.createMap();
result.putString("type", "cancel");
mOpenBrowserPromise.resolve(result);
mOpenBrowserPromise = null;
}
}
Loading

0 comments on commit 0e6372a

Please sign in to comment.