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

Adding new functionalities #109

Open
wants to merge 2 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/jsLinters/jshint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/react-native-safari-view-kzen.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,30 @@ __Example__
SafariView.dismiss()
```

### hide()
hide the currently active Safari View.

__Example__
```js
SafariView.hide()
```

### unhide()
unhide the currently active Safari View.

__Example__
```js
SafariView.unHide()
```

### isInit()
Checks if Safari View was initialized by .show() .

__Example__
```js
SafariView.isInit()
```

## Events
The following events are fired by the Safari View.

Expand Down
14 changes: 13 additions & 1 deletion SafariViewManager.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ export default {
NativeSafariViewManager.dismiss();
},

hide() {
NativeSafariViewManager.hide();
},

unHide() {
NativeSafariViewManager.unHide();
},
isInit() {
return NativeSafariViewManager.isInit();
},

isAvailable() {
return NativeSafariViewManager.isAvailable();
},
Expand All @@ -39,7 +50,8 @@ export default {
} else {
console.warn(`Trying to subscribe to unknown event: ${event}`);
return {
remove: () => {}
remove: () => {
}
};
}
},
Expand Down
40 changes: 39 additions & 1 deletion SafariViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@
@implementation SafariViewManager
{
bool hasListeners;
bool isInitialized;
SFSafariViewController *_safariView;
}

-(id)init{
if ((self = [super init]))
{
isInitialized = NO;
}
return self;
}


+ (BOOL)requiresMainQueueSetup{
return true;
}

RCT_EXPORT_MODULE()

- (dispatch_queue_t)methodQueue
Expand Down Expand Up @@ -75,9 +89,10 @@ - (void)stopObserving

// get the view controller closest to the foreground
UIViewController *ctrl = RCTPresentedViewController();

// Display the Safari View
[ctrl presentViewController:_safariView animated:YES completion:nil];
isInitialized = YES;

if (hasListeners) {
[self sendEventWithName:@"SafariViewOnShow" body:nil];
Expand All @@ -99,6 +114,29 @@ - (void)stopObserving
RCT_EXPORT_METHOD(dismiss)
{
[_safariView dismissViewControllerAnimated:true completion:nil];
isInitialized = NO;
}

RCT_EXPORT_METHOD(hide)
{
_safariView.view.hidden=YES;
_safariView.view.setNeedsDisplay;
}

RCT_EXPORT_METHOD(unHide)
{
_safariView.view.hidden=NO;
_safariView.view.setNeedsDisplay;
}

RCT_EXPORT_METHOD(isInit:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
if(isInitialized){
resolve(@YES);
}
else{
reject(@"E_SAFARI_VIEW_UNINITIALIZED", @"SafariView is uninitialized", nil);
}
}

-(void)safariViewControllerDidFinish:(nonnull SFSafariViewController *)controller
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
77 changes: 77 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Type definitions for react-native-safari-view 2.0
// Project: https://github.com/naoufal/react-native-safari-view
// Definitions by: Michael Randolph <https://github.com/mrand01>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

import { EmitterSubscription } from 'react-native';

export interface SafariViewOptions {
/**
* A String containing the url you want to load in the Safari View
*
*/
url: string;

/**
* A Boolean indicating to use Safari's Reader Mode if available
*
*/
readerMode?: boolean;

/**
* A String containing a hex or rgba color to use for the browser controls
*
*/
tintColor?: string;

/**
* A String containing a hex or rgba color to use for the background of the browser controls (only available on iOS 10 and higher)
*
*/
barTintColor?: string;

/**
* A Boolean indicating to open the Safari View from the bottom
*
*/
fromBottom?: boolean;
}

declare namespace SafariView {
/**
* Displays a Safari View with the provided URL
*
*/
function show(options: SafariViewOptions): Promise<boolean>;

/**
* Dismisses the currently active Safari View
*/
function dismiss(): void;

/**
* Hide the currently active Safari View
*/
function hide(): void;

/**
* Un-Hide the currently active Safari View
*/
function unHide(): void;

/**
* isInit whether this view was set by show() or not. will be set to false after dismiss
*/
function isInit(): Promise<boolean>;

/**
* Checks if Safari View is available on the device
*/
function isAvailable(): Promise<boolean>;

function addEventListener(event: string, listener: () => void): EmitterSubscription;

function removeEventListener(event: string, listener: () => void): void;
}
export default SafariView;
Loading