Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-native): add getDeviceName util (#13015)
* feat(react-native): add getDeviceName util * code cleanup --------- Co-authored-by: Ashwin Kumar <ashwsrir@amazon.com> Co-authored-by: Venkata Ramyasri Kota <34170013+kvramyasri7@users.noreply.github.com>
- Loading branch information
1 parent
7ddca1b
commit 36b5d1e
Showing
7 changed files
with
84 additions
and
35 deletions.
There are no files selected for viewing
36 changes: 25 additions & 11 deletions
36
...eact-native/android/src/main/kotlin/com/amazonaws/amplify/rtncore/AmplifyRTNCoreModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.amazonaws.amplify.rtncore | ||
|
||
import android.os.Build | ||
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.Promise | ||
import com.facebook.react.bridge.ReadableMap | ||
|
||
class AmplifyRTNCoreModule(reactContext: ReactApplicationContext) : | ||
ReactContextBaseJavaModule(reactContext) { | ||
|
||
override fun getName(): String { | ||
return NAME | ||
} | ||
ReactContextBaseJavaModule(reactContext) { | ||
override fun getName(): String { | ||
return NAME | ||
} | ||
|
||
@ReactMethod | ||
fun computeModPow(payload: ReadableMap, promise: Promise) { | ||
fun computeModPow( | ||
payload: ReadableMap, | ||
promise: Promise, | ||
) { | ||
BigInteger.computeModPow(payload, promise) | ||
} | ||
|
||
@ReactMethod | ||
fun computeS(payload: ReadableMap, promise: Promise) { | ||
fun computeS( | ||
payload: ReadableMap, | ||
promise: Promise, | ||
) { | ||
BigInteger.computeS(payload, promise) | ||
} | ||
|
||
companion object { | ||
const val NAME = "AmplifyRTNCore" | ||
} | ||
@ReactMethod | ||
fun getDeviceName(promise: Promise) { | ||
promise.resolve(Build.MODEL) | ||
} | ||
|
||
companion object { | ||
const val NAME = "AmplifyRTNCore" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,45 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#if canImport(UIKit) | ||
import UIKit | ||
#else | ||
import Foundation | ||
#endif | ||
|
||
@objc(AmplifyRTNCore) | ||
class AmplifyRTNCore: NSObject { | ||
|
||
@objc(multiply:withB:withResolver:withRejecter:) | ||
func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void { | ||
resolve(a*b) | ||
} | ||
|
||
@objc(computeModPow:withResolver:withRejecter:) | ||
func computeModPow( | ||
payload: [String: String], | ||
resolve: RCTPromiseResolveBlock, | ||
reject: RCTPromiseRejectBlock | ||
) -> Void { | ||
BigInteger.computeModPow(payload, resolve: resolve, reject: reject) | ||
} | ||
|
||
@objc(computeS:withResolver:withRejecter:) | ||
func computeS( | ||
_ payload: [String: String], | ||
resolve: RCTPromiseResolveBlock, | ||
reject: RCTPromiseRejectBlock | ||
) -> Void { | ||
BigInteger.computeS(payload, resolve: resolve, reject: reject) | ||
} | ||
@objc(multiply:withB:withResolver:withRejecter:) | ||
func multiply(a: Float, b: Float, resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock) { | ||
resolve(a * b) | ||
} | ||
|
||
@objc(computeModPow:withResolver:withRejecter:) | ||
func computeModPow( | ||
payload: [String: String], | ||
resolve: RCTPromiseResolveBlock, | ||
reject: RCTPromiseRejectBlock | ||
) { | ||
BigInteger.computeModPow(payload, resolve: resolve, reject: reject) | ||
} | ||
|
||
@objc(computeS:withResolver:withRejecter:) | ||
func computeS( | ||
_ payload: [String: String], | ||
resolve: RCTPromiseResolveBlock, | ||
reject: RCTPromiseRejectBlock | ||
) { | ||
BigInteger.computeS(payload, resolve: resolve, reject: reject) | ||
} | ||
|
||
@objc(getDeviceName:withResolver:) | ||
func getDeviceName(resolve: @escaping RCTPromiseResolveBlock, reject _: @escaping RCTPromiseRejectBlock) { | ||
var deviceName: String | ||
#if canImport(UIKit) | ||
deviceName = UIDevice.current.name | ||
#else | ||
deviceName = ProcessInfo.processInfo.hostName | ||
#endif | ||
resolve(deviceName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { nativeModule } from '../nativeModule'; | ||
import { RTNCore } from '../types'; | ||
|
||
export const getDeviceName: RTNCore['getDeviceName'] = () => | ||
nativeModule.getDeviceName(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,6 @@ export interface RTNCore { | |
b: string; | ||
u: string; | ||
}): Promise<string>; | ||
|
||
getDeviceName(): Promise<string>; | ||
} |