Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hidden option to allow use safari view only to read cookies #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,24 @@ class YourComponent extends Component {
Displays a Safari View with the provided url.

__Arguments__
- `safariOptions` - An `Object` containing a `url` key and optionally a `readerMode` key, a `tintColor`, and/or a `barTintColor`.
- `safariOptions` - An `Object` containing a `url` key and optionally a `readerMode` key, a `tintColor`, a `barTintColor`, and/or a `hidden`.

__safariOptions__
- `url` - A `String` containing the url you want to load in the Safari View
- `readerMode` - A `Boolean` indicating to use Safari's Reader Mode if available
- `tintColor` - A `String` containing a hex, rgba or rgba color to use for the browser controls
- `barTintColor` - A `String` containing a hex, rgba or rgba color to use for the background of the browser controls (only available on iOS 10 and higher)
- `fromBottom` - A 'Boolean' indicating to open the Safari View from the bottom
- `hidden` - A 'Boolean' indicating if Safari View will appear or not. If true, it means the Safari View is only to read Safari's cookies

__Examples__
```js
SafariView.show({
url: "http://facebook.github.io/react/blog/2015/03/26/introducing-react-native.html",
readerMode: true // optional,
tintColor: "#000" // optional
barTintColor: "#fff" // optional
barTintColor: "#fff" // optional,
hidden: true // optional
});
```

Expand Down
15 changes: 13 additions & 2 deletions SafariViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ - (void)stopObserving
UIColor *tintColorString = args[@"tintColor"];
UIColor *barTintColorString = args[@"barTintColor"];
BOOL fromBottom = [args[@"fromBottom"] boolValue];
BOOL hidden = [args[@"hidden"] boolValue];

// Initialize the Safari View
self.safariView = [[SFSafariViewController alloc] initWithURL:url entersReaderIfAvailable:readerMode];
Expand Down Expand Up @@ -75,8 +76,18 @@ - (void)stopObserving
// get the view controller closest to the foreground
UIViewController *ctrl = RCTPresentedViewController();

// Display the Safari View
[ctrl presentViewController:self.safariView animated:YES completion:nil];
if (hidden) {
// reference from https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller
self.safariView.view.userInteractionEnabled = NO;
self.safariView.view.alpha = 0.05;
[ctrl addChildViewController:self.safariView];
[ctrl.view addSubview:self.safariView.view];
[self.safariView didMoveToParentViewController:ctrl];
self.safariView.view.frame = CGRectMake(0.0, 0.0, 0.5, 0.5);
} else {
// Display the Safari View
[ctrl presentViewController:self.safariView animated:YES completion:nil];
}

if (hasListeners) {
[self sendEventWithName:@"SafariViewOnShow" body:nil];
Expand Down