vialink-react-native-sdk 3.0.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,11 +13,15 @@ class ViaLinkModule(reactContext: ReactApplicationContext) :
|
|
|
13
13
|
ActivityEventListener {
|
|
14
14
|
|
|
15
15
|
companion object {
|
|
16
|
-
const val WRAPPER_VERSION = "
|
|
16
|
+
const val WRAPPER_VERSION = "3.1.0"
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
|
|
20
|
+
/// onDeepLink가 listenerCount==0 시점에 호출된 경우의 캐시.
|
|
21
|
+
/// 3.1.0부터 일반 진입에서도 콜백이 호출되므로, link 진입(map != null) / 일반 진입(map == null)을
|
|
22
|
+
/// 구분하기 위해 별도 플래그(`hasPendingDeepLink`)를 둔다.
|
|
20
23
|
private var pendingDeepLink: WritableMap? = null
|
|
24
|
+
private var hasPendingDeepLink: Boolean = false
|
|
21
25
|
private var pendingDeferred: WritableMap? = null
|
|
22
26
|
private var listenerCount = 0
|
|
23
27
|
|
|
@@ -40,10 +44,15 @@ class ViaLinkModule(reactContext: ReactApplicationContext) :
|
|
|
40
44
|
ViaLinkSDK.setWrapper("react-native/$WRAPPER_VERSION")
|
|
41
45
|
ViaLinkSDK.init(context, apiKey)
|
|
42
46
|
|
|
47
|
+
// 딥링크 콜백 — SDK 3.1.0+: data == null이면 일반 진입을 의미한다.
|
|
48
|
+
// JS 측 emitter는 null payload를 그대로 전달받아 `data: null`로 콜백을 호출한다.
|
|
43
49
|
ViaLinkSDK.onDeepLink { data ->
|
|
44
|
-
val map = data
|
|
50
|
+
val map: WritableMap? = data?.toWritableMap()
|
|
45
51
|
if (listenerCount > 0) sendEvent("onDeepLink", map)
|
|
46
|
-
else
|
|
52
|
+
else {
|
|
53
|
+
pendingDeepLink = map
|
|
54
|
+
hasPendingDeepLink = true
|
|
55
|
+
}
|
|
47
56
|
}
|
|
48
57
|
// 디퍼드 콜백: SDK 3.0+ 시그니처 (data, error) — 항상 1회 호출
|
|
49
58
|
// JS 측 emit 페이로드는 `{data, error}` 객체로 전달한다.
|
|
@@ -166,10 +175,11 @@ class ViaLinkModule(reactContext: ReactApplicationContext) :
|
|
|
166
175
|
@ReactMethod
|
|
167
176
|
fun addListener(eventName: String) {
|
|
168
177
|
listenerCount++
|
|
169
|
-
// pending 이벤트 flush
|
|
170
|
-
if (eventName == "onDeepLink") {
|
|
171
|
-
|
|
178
|
+
// pending 이벤트 flush — 3.1.0부터 일반 진입(null payload)도 flush해야 한다.
|
|
179
|
+
if (eventName == "onDeepLink" && hasPendingDeepLink) {
|
|
180
|
+
sendEvent("onDeepLink", pendingDeepLink) // null payload도 그대로 전달
|
|
172
181
|
pendingDeepLink = null
|
|
182
|
+
hasPendingDeepLink = false
|
|
173
183
|
}
|
|
174
184
|
if (eventName == "onDeferredDeepLink") {
|
|
175
185
|
pendingDeferred?.let { sendEvent("onDeferredDeepLink", it) }
|
package/dist/ViaLinkSDK.d.ts
CHANGED
|
@@ -92,10 +92,23 @@ export declare class ViaLinkSDK {
|
|
|
92
92
|
*/
|
|
93
93
|
configure(apiKey: string): Promise<void>;
|
|
94
94
|
/**
|
|
95
|
-
* 딥링크 수신 콜백 등록
|
|
96
|
-
*
|
|
95
|
+
* 딥링크 수신 콜백 등록 (3.1.0+).
|
|
96
|
+
*
|
|
97
|
+
* 네이티브 SDK가 진입 알림(`handleIntent`/`handleUniversalLink`/`notifyAppLaunch`)을 처리할 때 항상 1회 호출됩니다.
|
|
98
|
+
* - App Links / Universal Links 진입이면 매칭된 [DeepLinkData]가 전달됩니다.
|
|
99
|
+
* - 일반 진입(아이콘 탭 등)이면 `null`이 전달됩니다.
|
|
100
|
+
*
|
|
101
|
+
* ```typescript
|
|
102
|
+
* ViaLinkSDK.shared.onDeepLink((data) => {
|
|
103
|
+
* if (!data) {
|
|
104
|
+
* // 일반 진입 — 기본 라우트 유지
|
|
105
|
+
* return;
|
|
106
|
+
* }
|
|
107
|
+
* navigation.navigate(data.path, data.params);
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
97
110
|
*/
|
|
98
|
-
onDeepLink(callback: (data: DeepLinkData) => void): void;
|
|
111
|
+
onDeepLink(callback: (data: DeepLinkData | null) => void): void;
|
|
99
112
|
/**
|
|
100
113
|
* 디퍼드 딥링크 콜백 등록
|
|
101
114
|
*
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var reactNative=require('react-native');var {ViaLinkSDK:r}=reactNative.NativeModules,i=new reactNative.NativeEventEmitter(r),l=/^[A-Za-z0-9_-]{1,100}$/,n=class a{constructor(){this.payment={initiated:async e=>{if(!e||typeof e!="object")throw new Error("args\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4.");if(typeof e.orderId!="string"||!l.test(e.orderId))throw new Error("order_id \uD615\uC2DD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4 (1~100\uC790, \uC601\uBB38/\uC22B\uC790/\uD558\uC774\uD508/\uC5B8\uB354\uC2A4\uCF54\uC5B4).");if(typeof e.amount!="number"||!Number.isFinite(e.amount)||e.amount<=0)throw new Error("amount\uB294 0\uBCF4\uB2E4 \uD070 \uC22B\uC790\uC5EC\uC57C \uD569\uB2C8\uB2E4.");if(typeof e.currency!="string"||e.currency.trim().length===0)throw new Error("currency\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4.");let t=await r.paymentInitiated({orderId:e.orderId,amount:e.amount,currency:e.currency.trim().toUpperCase(),linkId:e.linkId??null,paymentMethod:e.paymentMethod??null,metadata:e.metadata??null});return {success:!!t?.success,paymentEventId:String(t?.paymentEventId??"")}}};}static get shared(){return this._instance||(this._instance=new a),this._instance}async configure(e){await r.configure(e);}onDeepLink(e){this.deepLinkSub?.remove(),this.deepLinkSub=i.addListener("onDeepLink",e);}onDeferredDeepLink(e){this.deferredSub?.remove(),this.deferredSub=i.addListener("onDeferredDeepLink",t=>{e(t?.data??null,t?.error??null);});}track(e,t){r.track(e,t??null);}async createLink(e,t,o,
|
|
1
|
+
'use strict';var reactNative=require('react-native');var {ViaLinkSDK:r}=reactNative.NativeModules,i=new reactNative.NativeEventEmitter(r),l=/^[A-Za-z0-9_-]{1,100}$/,n=class a{constructor(){this.payment={initiated:async e=>{if(!e||typeof e!="object")throw new Error("args\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4.");if(typeof e.orderId!="string"||!l.test(e.orderId))throw new Error("order_id \uD615\uC2DD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4 (1~100\uC790, \uC601\uBB38/\uC22B\uC790/\uD558\uC774\uD508/\uC5B8\uB354\uC2A4\uCF54\uC5B4).");if(typeof e.amount!="number"||!Number.isFinite(e.amount)||e.amount<=0)throw new Error("amount\uB294 0\uBCF4\uB2E4 \uD070 \uC22B\uC790\uC5EC\uC57C \uD569\uB2C8\uB2E4.");if(typeof e.currency!="string"||e.currency.trim().length===0)throw new Error("currency\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4.");let t=await r.paymentInitiated({orderId:e.orderId,amount:e.amount,currency:e.currency.trim().toUpperCase(),linkId:e.linkId??null,paymentMethod:e.paymentMethod??null,metadata:e.metadata??null});return {success:!!t?.success,paymentEventId:String(t?.paymentEventId??"")}}};}static get shared(){return this._instance||(this._instance=new a),this._instance}async configure(e){await r.configure(e);}onDeepLink(e){this.deepLinkSub?.remove(),this.deepLinkSub=i.addListener("onDeepLink",t=>{e(t??null);});}onDeferredDeepLink(e){this.deferredSub?.remove(),this.deferredSub=i.addListener("onDeferredDeepLink",t=>{e(t?.data??null,t?.error??null);});}track(e,t){r.track(e,t??null);}async createLink(e,t,o,d="static",s){return r.createLink(e,t??null,o??null,d,s??null)}destroy(){this.deepLinkSub?.remove(),this.deferredSub?.remove();}};exports.ViaLinkSDK=n;
|
package/ios/ViaLinkModule.swift
CHANGED
|
@@ -5,9 +5,13 @@ import ViaLinkCore // xcframework module: ViaLinkCore (class: ViaLinkSDK)
|
|
|
5
5
|
@objc(ViaLinkSDK)
|
|
6
6
|
class ViaLinkModule: RCTEventEmitter {
|
|
7
7
|
|
|
8
|
-
static let wrapperVersion = "
|
|
8
|
+
static let wrapperVersion = "3.1.0"
|
|
9
9
|
|
|
10
|
+
/// onDeepLink가 hasListeners == false 시점에 호출된 경우의 캐시.
|
|
11
|
+
/// 3.1.0부터 일반 진입(nil payload)도 콜백이 호출되므로, link 진입(map != nil) /
|
|
12
|
+
/// 일반 진입(map == nil)을 구분하기 위해 별도 플래그(`hasPendingDeepLink`)를 둔다.
|
|
10
13
|
private var pendingDeepLink: [String: Any?]?
|
|
14
|
+
private var hasPendingDeepLink: Bool = false
|
|
11
15
|
private var pendingDeferred: [String: Any?]?
|
|
12
16
|
private var hasListeners = false
|
|
13
17
|
|
|
@@ -20,9 +24,11 @@ class ViaLinkModule: RCTEventEmitter {
|
|
|
20
24
|
|
|
21
25
|
override func startObserving() {
|
|
22
26
|
hasListeners = true
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
// 3.1.0+: pendingDeepLink가 nil이어도 hasPendingDeepLink가 true면 일반 진입 콜백을 flush한다.
|
|
28
|
+
if hasPendingDeepLink {
|
|
29
|
+
sendEvent(withName: "onDeepLink", body: pendingDeepLink as Any)
|
|
25
30
|
pendingDeepLink = nil
|
|
31
|
+
hasPendingDeepLink = false
|
|
26
32
|
}
|
|
27
33
|
if let pending = pendingDeferred {
|
|
28
34
|
sendEvent(withName: "onDeferredDeepLink", body: pending)
|
|
@@ -37,12 +43,15 @@ class ViaLinkModule: RCTEventEmitter {
|
|
|
37
43
|
ViaLinkSDK.shared.setWrapper("react-native/\(Self.wrapperVersion)")
|
|
38
44
|
ViaLinkSDK.shared.configure(apiKey: apiKey)
|
|
39
45
|
|
|
46
|
+
// 딥링크 콜백 — SDK 3.1.0+: data == nil이면 일반 진입을 의미한다.
|
|
47
|
+
// JS 측 emitter는 null payload를 그대로 전달받아 `data: null`로 콜백을 호출한다.
|
|
40
48
|
ViaLinkSDK.shared.onDeepLink { [weak self] data in
|
|
41
|
-
let map = data
|
|
49
|
+
let map: [String: Any?]? = data?.toDictionary()
|
|
42
50
|
if self?.hasListeners == true {
|
|
43
|
-
self?.sendEvent(withName: "onDeepLink", body: map)
|
|
51
|
+
self?.sendEvent(withName: "onDeepLink", body: map as Any)
|
|
44
52
|
} else {
|
|
45
53
|
self?.pendingDeepLink = map
|
|
54
|
+
self?.hasPendingDeepLink = true
|
|
46
55
|
}
|
|
47
56
|
}
|
|
48
57
|
|
package/package.json
CHANGED