-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[facebook][android] Rewrite facebook module to Kotlin #14572
[facebook][android] Rewrite facebook module to Kotlin #14572
Conversation
Co-authored-by: Expo CI <[email protected]>
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.
Nice! A few suggestions on how I'd do that, but they're up to you
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
if (FacebookSdk.getApplicationId() == null) { | ||
promise.reject( | ||
ERR_FACEBOOK_MISCONFIGURED, | ||
"No appId configured, required for initialization. " + | ||
"Please ensure that you're either providing `appId` to `initializeAsync` as an argument or inside AndroidManifest.xml." | ||
) | ||
} |
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.
Not directly related to this PR, but shouldn't the method return here as the promise is rejected anyway? I see the return
was missing in Java too. 🤔
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.
We for sure should add the return here. I guess anyone noticed that cause on Android, you can resolve promise multiple times - what btw is stupid 🤷♂️
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookPackage.kt
Outdated
Show resolved
Hide resolved
…ach60161/expo into @mstach60161/rewrite-facebook-module
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
if (FacebookSdk.getApplicationId() == null) { | ||
promise.reject( | ||
ERR_FACEBOOK_MISCONFIGURED, | ||
"No appId configured, required for initialization. " + | ||
"Please ensure that you're either providing `appId` to `initializeAsync` as an argument or inside AndroidManifest.xml." | ||
) | ||
} |
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.
We for sure should add the return here. I guess anyone noticed that cause on Android, you can resolve promise multiple times - what btw is stupid 🤷♂️
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
@ExpoMethod | ||
fun getAdvertiserIDAsync(promise: Promise) { | ||
try { | ||
promise.resolve(attributionIdentifiers!!.androidAdvertiserId) |
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.
and here
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 think we reject in catch block (same in suggestions below) but if it's bad practise (?) , I can change it.
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.
hmm, you are right, but I don't like this. I think we should avoid using the try-catch block. It'll look better that way in my opinion. Also, it's more self-explanatory.
@ExpoMethod | ||
fun getAttributionIDAsync(promise: Promise) { | ||
try { | ||
promise.resolve(attributionIdentifiers!!.attributionId) |
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.
here too
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
@ExpoMethod | ||
fun flushAsync(promise: Promise) { | ||
try { | ||
appEventLogger!!.flush() |
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.
reject 🤔
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookPackage.kt
Outdated
Show resolved
Hide resolved
private val ERR_FACEBOOK_MISCONFIGURED = "ERR_FACEBOOK_MISCONFIGURED" | ||
private val ERR_FACEBOOK_LOGIN = "ERR_FACEBOOK_LOGIN" | ||
private val PUSH_PAYLOAD_KEY = "fb_push_payload" | ||
private val PUSH_PAYLOAD_CAMPAIGN_KEY = "campaign" |
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 think @lukmccall meant to move these constants outside class definition 😄
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.
Yep, exactly 😅
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.
Looks good
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Outdated
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookModule.kt
Show resolved
Hide resolved
packages/expo-facebook/android/src/main/java/expo/modules/facebook/FacebookPackage.kt
Outdated
Show resolved
Hide resolved
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.
As for me it looks fine 👍
This module might not be the most elegant one, but the conversion looks fine.
Refer to the comments from others and we're ready to ship it 🚢
…ach60161/expo into @mstach60161/rewrite-facebook-module
Why
Java modules are rewritten to kotlin.
How
Test Plan
Checklist