Skip to content

Commit 10ba159

Browse files
committed
feat(share-intent): improve type safety and initialization order
- Change return type from `SharePayload | null` to `SharePayload | undefined` in TypeScript interface for better type safety - Move initialization block after method definitions for better code organization - Add NullType import for Android implementation - Maintain same functionality while improving code structure and type consistency
1 parent 2095389 commit 10ba159

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

android/src/main/java/com/margelo/nitro/nitroshareintent/NitroShareIntent.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import java.io.FileOutputStream
2525
import java.util.Date
2626
import androidx.core.net.toUri
2727
import com.facebook.react.bridge.ActivityEventListener
28+
import com.margelo.nitro.core.NullType
2829

2930
@DoNotStrip
3031
class NitroShareIntent : HybridNitroShareIntentSpec(), ActivityEventListener{
@@ -46,15 +47,7 @@ class NitroShareIntent : HybridNitroShareIntentSpec(), ActivityEventListener{
4647
}
4748
}
4849

49-
init {
50-
NitroModules.applicationContext.let { ctx->
51-
ctx?.addActivityEventListener(this)
52-
}
53-
}
54-
55-
5650
override fun getInitialShare(): Promise<SharePayload?> {
57-
5851
val intent = NitroModules.applicationContext?.currentActivity?.intent
5952

6053
return if (intent != null && isShareIntent(intent)) {
@@ -65,6 +58,12 @@ class NitroShareIntent : HybridNitroShareIntentSpec(), ActivityEventListener{
6558
}
6659
}
6760

61+
init {
62+
NitroModules.applicationContext.let { ctx->
63+
ctx?.addActivityEventListener(this)
64+
}
65+
}
66+
6867
override fun onIntentListener(listener: (SharePayload) -> Unit): Double {
6968
intentListener = listener
7069
nextListenerId++

src/NitroShareIntent.nitro.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export type SharePayload = {
1111

1212
export interface NitroShareIntent
1313
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
14-
getInitialShare(): Promise<SharePayload | null>;
14+
getInitialShare(): Promise<SharePayload | undefined>;
1515
onIntentListener(listener: (payload: SharePayload) => void): number;
1616
}

0 commit comments

Comments
 (0)