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
feat(react-native): add getDeviceName util #13015
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5f1f86e
feat(react-native): add getDeviceName util
867ca76
Merge branch 'main' into rn-getDeviceName
ashwinkumar6 5b6c2b7
code cleanup
5255143
Merge branch 'main' into rn-getDeviceName
kvramyasri7 b388b66
Merge branch 'main' into rn-getDeviceName
ashwinkumar6 5006e37
Merge branch 'main' into rn-getDeviceName
ashwinkumar6 d675fed
Merge branch 'main' into rn-getDeviceName
ashwinkumar6 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of the
name
getter of theUIDevice
class requires the host app to be assigned with a corresponding entitlement (when running on iOS 16.0+) otherwise it returns the generic string"iPhone"
, are we going to instruct developers to do so in order to use this API?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should instruct developers to add a corresponding entitlement to use the API since it defaults to a generic device name, example "iPhone"
We could add a callout saying by default