Skip to content

Commit

Permalink
Merge pull request #1 from HarshaR1642/ios
Browse files Browse the repository at this point in the history
Added iOS changes
  • Loading branch information
HarshaR1642 authored Oct 4, 2024
2 parents c8beedb + c1fc167 commit f39e566
Show file tree
Hide file tree
Showing 26 changed files with 104 additions and 57 deletions.
2 changes: 1 addition & 1 deletion android/src/main/java/com/bridge/api/ActivityManagerAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ActivityManagerAPI {
val resultCode = when (result) {
"ok" -> Activity.RESULT_OK
"cancel" -> Activity.RESULT_CANCELED
else -> Activity.RESULT_OK
else -> -2
}

val intent = Intent()
Expand Down
12 changes: 12 additions & 0 deletions ios/Bridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ @interface RCT_EXTERN_MODULE(Bridge, NSObject)

RCT_EXTERN_METHOD(isPackageInstalled:(NSString *)packageName withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(returnAuthCode:(NSString *)code
state:(NSString *)state
redirectUri:(NSString *)redirectUri
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(returnError:(NSString *)redirectUri
error:(NSString *)error
errorDescription:(NSString *)errorDescription
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

+ (BOOL)requiresMainQueueSetup
{
return NO;
Expand Down
38 changes: 37 additions & 1 deletion ios/Bridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,40 @@ class Bridge: NSObject {
resolve(false)
}
}
}

@objc(returnAuthCode:state:redirectUri:resolver:rejecter:)
func returnAuthCode(code: String, state: String, redirectUri: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
if let redirectURL = URL(string: redirectUri) {
var components = URLComponents(url: redirectURL, resolvingAgainstBaseURL: false)

let paramAuthCode = URLQueryItem(name: "code", value: code)
let paramState = URLQueryItem(name: "state", value: state)
components?.queryItems = [paramAuthCode, paramState]

if let resultURL = components?.url {
UIApplication.shared.open(resultURL, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly: true], completionHandler: nil)
}
} else {
let error = NSError(domain: "googleHome", code: 0, userInfo: [NSLocalizedDescriptionKey: "redirectUri is invalid"])
reject("0", "redirectUri is nil", error)
}
}

@objc(returnError:error:errorDescription:resolver:rejecter:)
func returnError(redirectUri: String, error: String, errorDescription: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
if let redirectURL = URL(string: redirectUri) {
var components = URLComponents(url: redirectURL, resolvingAgainstBaseURL: false)

let paramError = URLQueryItem(name: "error", value: error)
let paramDescription = URLQueryItem(name: "error_description", value: errorDescription)
components?.queryItems = [paramError, paramDescription]

if let resultURL = components?.url {
UIApplication.shared.open(resultURL, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly: true], completionHandler: nil)
}
} else {
let error = NSError(domain: "googleHome", code: 0, userInfo: [NSLocalizedDescriptionKey: "redirectUri is invalid"])
reject("0", "redirectUri is nil", error)
}
}
}
12 changes: 12 additions & 0 deletions lib/commonjs/ActivityManager.js

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

2 changes: 1 addition & 1 deletion lib/commonjs/ActivityManager.js.map

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

1 change: 0 additions & 1 deletion lib/commonjs/package.json

This file was deleted.

6 changes: 0 additions & 6 deletions lib/commonjs/types/ActivityManager.d.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/commonjs/types/ActivityManager.d.js.map

This file was deleted.

6 changes: 0 additions & 6 deletions lib/commonjs/types/PackageManager.d.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/commonjs/types/PackageManager.d.js.map

This file was deleted.

13 changes: 0 additions & 13 deletions lib/commonjs/types/index.d.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/commonjs/types/index.d.js.map

This file was deleted.

12 changes: 11 additions & 1 deletion lib/module/ActivityManager.js

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

2 changes: 1 addition & 1 deletion lib/module/ActivityManager.js.map

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

1 change: 0 additions & 1 deletion lib/module/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions lib/module/types/ActivityManager.d.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/module/types/ActivityManager.d.js.map

This file was deleted.

4 changes: 0 additions & 4 deletions lib/module/types/PackageManager.d.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/module/types/PackageManager.d.js.map

This file was deleted.

6 changes: 0 additions & 6 deletions lib/module/types/index.d.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/module/types/index.d.js.map

This file was deleted.

4 changes: 3 additions & 1 deletion lib/typescript/commonjs/src/ActivityManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ type extrasType = {
[key: string]: number | string | boolean;
};
declare function setResultAndFinish(result: resultType, extras: extrasType): void;
export { setResultAndFinish };
declare function returnAuthCode(code: string, state: string, redirectUri: string): void;
declare function returnError(redirectUri: string, error: string, errorDescription?: string): void;
export { setResultAndFinish, returnAuthCode, returnError };
//# sourceMappingURL=ActivityManager.d.ts.map
2 changes: 1 addition & 1 deletion lib/typescript/commonjs/src/ActivityManager.d.ts.map

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

4 changes: 3 additions & 1 deletion lib/typescript/module/src/ActivityManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ type extrasType = {
[key: string]: number | string | boolean;
};
declare function setResultAndFinish(result: resultType, extras: extrasType): void;
export { setResultAndFinish };
declare function returnAuthCode(code: string, state: string, redirectUri: string): void;
declare function returnError(redirectUri: string, error: string, errorDescription?: string): void;
export { setResultAndFinish, returnAuthCode, returnError };
//# sourceMappingURL=ActivityManager.d.ts.map
2 changes: 1 addition & 1 deletion lib/typescript/module/src/ActivityManager.d.ts.map

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

22 changes: 21 additions & 1 deletion src/ActivityManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,24 @@ function setResultAndFinish(result: resultType, extras: extrasType): void {
}
}

export { setResultAndFinish };
function returnAuthCode(
code: string,
state: string,
redirectUri: string
): void {
if (Platform.OS === 'ios') {
Bridge.returnAuthCode(code, state, redirectUri);
}
}

function returnError(
redirectUri: string,
error: string,
errorDescription: string = ''
): void {
if (Platform.OS === 'ios') {
Bridge.returnError(redirectUri, error, errorDescription);
}
}

export { setResultAndFinish, returnAuthCode, returnError };

0 comments on commit f39e566

Please sign in to comment.