-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Firebase setup - Added Android native method for requesting permissions and fetching device tokens. #3
feat: Firebase setup - Added Android native method for requesting permissions and fetching device tokens. #3
Conversation
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! thanks for this, few comments.
Last part is the listeners: https://reactnative.dev/docs/native-modules-android#sending-events-to-javascript
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 🚀
…missions and fetching device tokens.
ce28712
to
78d1235
Compare
fix: add new auth method and update readme
a28ff16
to
f400bce
Compare
#1 adds the first part; now, all that is left is the emitter part (https://reactnative.dev/docs/native-modules-android#sending-events-to-javascript) @vijaygojiya Let me know if you want to tackle that. I'm imagining something like this: class PushPackage : ReactPackage {
data class Action (val type: String, val payload: Map<String, Any?>)
private var isInitialized = false
private val queue = mutableListOf<Action>()
private var module: PushModule? = null
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
module = PushModule(reactContext)
module?.onInitialized = {
isInitialized = true
queue.forEach {
module?.dispatch(it.type, it.payload)
}
queue.clear()
}
return listOf(module as NativeModule)
}
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
return emptyList()
}
fun dispatch(action: String, payload: Map<String, Any?>) {
if (isInitialized) {
module?.dispatch(action, payload)
} else {
queue.add(Action(action, payload))
}
}
} // in PushModule companion object {
const val notificationReceived = "notificationReceived"
const val deviceTokenReceived = "deviceTokenReceived"
const val errorReceived = "errorReceived"
}
override fun getConstants() = mapOf(
...
)
// Example method
// See https://reactnative.dev/docs/native-modules-android
@ReactMethod
fun addListener(eventName: String?) {
// Keep: Required for RN built in Event Emitter Calls.
}
@ReactMethod
fun removeListeners(count: Int?) {
// Keep: Required for RN built in Event Emitter Calls.
}
fun dispatch(action: String, payload: Map<String, Any?>) {
val map = mapOf(
"type" to action,
"payload" to payload
)
val event: WritableMap = Arguments.makeNativeMap(map)
reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit("...", event)
} |
Yes, I will take care of this today. Thanks |
@gtokman Could you please review my implementation for the events emitter?. also need help on understanding event queue and dispatching event actions. |
android/src/main/java/com/candlefinance/push/MyFirebaseMessagingService.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/candlefinance/push/MyFirebaseMessagingService.kt
Outdated
Show resolved
Hide resolved
private val CHANNEL_ID = "RNFireDefaultChannelID" | ||
private val CHANNEL_NAME = "Firebase Default" | ||
private val NOTIFICATION_ID = 123321 |
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.
#? do we need to inject these from the JS side? If so, we might need to add an init function. I have ideas but never done Android push.
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.
- Will do more R& D on it and improve.
.setSmallIcon(getResourceIdByName("ic_launcher","mipmap")) | ||
.setContentTitle(title) | ||
.setContentText(message) |
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.
#? do we need to inject this, too? Is this like the app icon shown in the push?
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.
Essentially, we now require an icon when sending notifications, and I've also introduced a feature to easily change this icon. Developers can customize the notification icon by adding a new asset to the 'drawable' folder with the exact name ic_default_notification
.
android/src/main/java/com/candlefinance/push/MyFirebaseMessagingService.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/candlefinance/push/RNEventEmitter.java
Outdated
Show resolved
Hide resolved
android/src/main/java/com/candlefinance/push/RNEventEmitter.java
Outdated
Show resolved
Hide resolved
android/src/main/java/com/candlefinance/push/ContextHolder.java
Outdated
Show resolved
Hide resolved
We probably don't need the queue, but you are good with the RNEmitter singleton you made regarding the dispatching events. After responding to my feedback, I will prob have to make a demo app on Firebase and see if this works. |
No description provided.