@flybits/react-native-concierge 0.0.0 → 0.1.8
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.
- package/LICENSE +20 -0
- package/README.md +75 -0
- package/android/build.gradle +102 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/concierge/AuthModule.kt +104 -0
- package/android/src/main/java/com/concierge/ConciergePackage.kt +19 -0
- package/android/src/main/java/com/concierge/ConciergeViewManager.kt +280 -0
- package/android/src/main/java/com/concierge/FlybitsModule.kt +460 -0
- package/android/src/main/java/com/concierge/UtilityHelper.kt +57 -0
- package/ios/Concierge-Bridging-Header.h +1 -0
- package/ios/ConciergeViewManager.m +40 -0
- package/ios/ConciergeViewManager.swift +158 -0
- package/ios/FlybitsModuleSwift.swift +489 -0
- package/lib/commonjs/index.js +260 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +259 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +41 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/index.d.ts +41 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +189 -8
- package/react-native-concierge.podspec +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Flybits
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+

|
|
2
|
+
# react-native-concierge
|
|
3
|
+
A React Native wrapper for the Flybits Concierge solution that brings personalized UI and Content into your React Native applications.
|
|
4
|
+
|
|
5
|
+
## Quickstart
|
|
6
|
+
|
|
7
|
+
Here is the bare minimum code required to quickly integrate Concierge to your React Native application.
|
|
8
|
+
|
|
9
|
+
More information can be referenced at [React Native Concierge SDK](https://flybits.gitbook.io/customer-documentation)
|
|
10
|
+
|
|
11
|
+
1. Install
|
|
12
|
+
```sh
|
|
13
|
+
npm install react-native-concierge --save
|
|
14
|
+
```
|
|
15
|
+
2. Configure
|
|
16
|
+
```javascript
|
|
17
|
+
import {
|
|
18
|
+
configure,
|
|
19
|
+
} from '@flybits/react-native-concierge';
|
|
20
|
+
|
|
21
|
+
configure({
|
|
22
|
+
projectId: '<your project ID>',
|
|
23
|
+
gateway: 'https://api.$REGION.flybits.com',
|
|
24
|
+
webService: 'https://static-files-concierge.$REGION.flybits.com/latest',
|
|
25
|
+
pushNetwork: 'fcm', // 'fcm' | 'apns' | 'huawei'
|
|
26
|
+
locationPlugin: true,
|
|
27
|
+
logLevel: 'debug',
|
|
28
|
+
locales: JSON.stringify(['en-ca', 'en']),
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
3. Authenticate
|
|
32
|
+
```javascript
|
|
33
|
+
import {
|
|
34
|
+
connect,
|
|
35
|
+
} from '@flybits/react-native-concierge';
|
|
36
|
+
|
|
37
|
+
const resultJson = JSON.parse(await connect());
|
|
38
|
+
if (resultJson.success) {
|
|
39
|
+
console.log(`Connected: ${resultJson.result}`);
|
|
40
|
+
} else {
|
|
41
|
+
console.log(`Error: ${resultJson.message}`);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
4. Display
|
|
45
|
+
```javascript
|
|
46
|
+
import {
|
|
47
|
+
Concierge,
|
|
48
|
+
ConciergeAction,
|
|
49
|
+
} from '@flybits/react-native-concierge';
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
export const ConciergeScreen = () => {
|
|
53
|
+
...
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<Concierge
|
|
57
|
+
actionlink={
|
|
58
|
+
{
|
|
59
|
+
action: 'concierge',
|
|
60
|
+
params: { zoneReferenceId: 'default_zone' },
|
|
61
|
+
} as ConciergeAction
|
|
62
|
+
}
|
|
63
|
+
/>
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
println('android/build.gradle invoked.')
|
|
2
|
+
buildscript {
|
|
3
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
4
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") :
|
|
5
|
+
project.properties["Concierge_kotlinVersion"]
|
|
6
|
+
|
|
7
|
+
repositories {
|
|
8
|
+
google()
|
|
9
|
+
mavenCentral()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
dependencies {
|
|
13
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
14
|
+
// noinspection DifferentKotlinGradleVersion
|
|
15
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def reactNativeArchitectures() {
|
|
20
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
21
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
def isNewArchitectureEnabled() {
|
|
25
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
apply plugin: "com.android.library"
|
|
29
|
+
apply plugin: "kotlin-android"
|
|
30
|
+
|
|
31
|
+
if (isNewArchitectureEnabled()) {
|
|
32
|
+
apply plugin: "com.facebook.react"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
def getExtOrDefault(name) {
|
|
36
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Concierge_" + name]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
def getExtOrIntegerDefault(name) {
|
|
40
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Concierge_" + name]).toInteger()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
def supportsNamespace() {
|
|
44
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
45
|
+
def major = parsed[0].toInteger()
|
|
46
|
+
def minor = parsed[1].toInteger()
|
|
47
|
+
|
|
48
|
+
// Namespace support was added in 7.3.0
|
|
49
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
android {
|
|
53
|
+
if (supportsNamespace()) {
|
|
54
|
+
namespace "com.concierge"
|
|
55
|
+
|
|
56
|
+
sourceSets {
|
|
57
|
+
main {
|
|
58
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
64
|
+
|
|
65
|
+
defaultConfig {
|
|
66
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
67
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
buildTypes {
|
|
71
|
+
release {
|
|
72
|
+
minifyEnabled false
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
lintOptions {
|
|
77
|
+
disable "GradleCompatible"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
compileOptions {
|
|
81
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
82
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
repositories {
|
|
87
|
+
mavenCentral()
|
|
88
|
+
google()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
92
|
+
|
|
93
|
+
dependencies {
|
|
94
|
+
// For < 0.71, this will be from the local maven repo
|
|
95
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
96
|
+
//noinspection GradleDynamicVersion
|
|
97
|
+
implementation "com.facebook.react:react-native:+"
|
|
98
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
99
|
+
|
|
100
|
+
api "com.flybits.android:concierge:5.1.5"
|
|
101
|
+
}
|
|
102
|
+
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import android.content.Context
|
|
2
|
+
import android.util.Log
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReactContext
|
|
6
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
7
|
+
import com.facebook.react.bridge.ReactMethod
|
|
8
|
+
import com.facebook.react.bridge.WritableMap
|
|
9
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
+
import com.flybits.commons.library.api.FlybitsManager
|
|
11
|
+
import com.flybits.commons.library.api.FlybitsScope
|
|
12
|
+
import com.flybits.commons.library.api.ScopeAuthState
|
|
13
|
+
import com.flybits.commons.library.models.User
|
|
14
|
+
import org.json.JSONObject
|
|
15
|
+
|
|
16
|
+
const val TAG_AUTH_MODULE = "AuthModule"
|
|
17
|
+
|
|
18
|
+
class AuthModule internal constructor(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
19
|
+
override fun getName(): String {
|
|
20
|
+
return "Auth"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private val authModuleScope = AuthModuleScope()
|
|
24
|
+
|
|
25
|
+
private var listenerCount = 0
|
|
26
|
+
|
|
27
|
+
internal fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap?) {
|
|
28
|
+
reactContext
|
|
29
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
30
|
+
.emit(eventName, params)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@ReactMethod
|
|
34
|
+
fun addListener(eventName: String) {
|
|
35
|
+
if (listenerCount == 0) {
|
|
36
|
+
FlybitsManager.addScope(authModuleScope, reactContext)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
listenerCount += 1
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactMethod
|
|
43
|
+
fun removeListeners(count: Int) {
|
|
44
|
+
listenerCount -= count
|
|
45
|
+
if (listenerCount == 0) {
|
|
46
|
+
FlybitsManager.removeScope(authModuleScope)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private inner class AuthModuleScope: FlybitsScope("ConciergeViewManagerScope") {
|
|
51
|
+
override fun onConnected(context: Context, user: User) {
|
|
52
|
+
val params = Arguments.createMap().apply {
|
|
53
|
+
val body = Arguments.createMap()
|
|
54
|
+
body.putString("authState", scopeAuthStateAsString(ScopeAuthState.CONNECTED_OPT_IN))
|
|
55
|
+
putMap("body", body)
|
|
56
|
+
}
|
|
57
|
+
sendEvent(reactContext = reactContext, eventName = "Authentication-onStart", params = params)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override fun onConnecting() {
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
override fun onDisconnected(context: Context) {
|
|
65
|
+
val params = Arguments.createMap().apply {
|
|
66
|
+
val body =Arguments.createMap()
|
|
67
|
+
body.putString("authState", scopeAuthStateAsString(ScopeAuthState.DISCONNECTED))
|
|
68
|
+
putMap("body", body)
|
|
69
|
+
}
|
|
70
|
+
sendEvent(reactContext = reactContext, eventName = "Authentication-onStart", params = params)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
override fun onFailedToConnect() {
|
|
74
|
+
// No-op
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
override fun onOptedStateChange(context: Context, optedState: Boolean) {
|
|
78
|
+
// No-op
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
override fun onStart(authState: ScopeAuthState) {
|
|
82
|
+
val params = Arguments.createMap().apply {
|
|
83
|
+
val body =Arguments.createMap()
|
|
84
|
+
body.putString("authState", scopeAuthStateAsString(authState))
|
|
85
|
+
putMap("body", body)
|
|
86
|
+
}
|
|
87
|
+
sendEvent(reactContext = reactContext, eventName = "Authentication-onStart", params = params)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
override fun onStop() {
|
|
91
|
+
// No-op
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private fun scopeAuthStateAsString(authState: ScopeAuthState) : String {
|
|
95
|
+
return when(authState) {
|
|
96
|
+
ScopeAuthState.DISCONNECTED -> "disconnected"
|
|
97
|
+
ScopeAuthState.CONNECTED_OPT_IN -> "connected"
|
|
98
|
+
ScopeAuthState.CONNECTED_OPT_OUT -> "connectedOptOut"
|
|
99
|
+
ScopeAuthState.CONNECTING -> "connecting"
|
|
100
|
+
ScopeAuthState.INITIATED -> "initiated"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.concierge
|
|
2
|
+
|
|
3
|
+
import AuthModule
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import com.facebook.react.ReactPackage
|
|
6
|
+
import com.facebook.react.bridge.NativeModule
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager
|
|
9
|
+
|
|
10
|
+
const val TAG_CONCIERGE_PACKAGE = "ConciergePackage"
|
|
11
|
+
class ConciergePackage : ReactPackage {
|
|
12
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
13
|
+
return listOf(FlybitsModule(reactContext), AuthModule(reactContext))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
17
|
+
return listOf(ConciergeViewManager(reactContext))
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
package com.concierge
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.content.BroadcastReceiver
|
|
5
|
+
import android.content.Context
|
|
6
|
+
import android.content.Intent
|
|
7
|
+
import android.content.IntentFilter
|
|
8
|
+
import android.net.Uri
|
|
9
|
+
import android.os.Build
|
|
10
|
+
import android.view.Choreographer
|
|
11
|
+
import android.view.View
|
|
12
|
+
import android.view.ViewGroup
|
|
13
|
+
import android.widget.FrameLayout
|
|
14
|
+
import androidx.core.content.ContextCompat
|
|
15
|
+
import androidx.fragment.app.Fragment
|
|
16
|
+
import androidx.fragment.app.FragmentActivity
|
|
17
|
+
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
|
18
|
+
import com.facebook.react.bridge.Arguments
|
|
19
|
+
import com.facebook.react.bridge.LifecycleEventListener
|
|
20
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
21
|
+
import com.facebook.react.bridge.ReadableArray
|
|
22
|
+
import com.facebook.react.bridge.ReadableMap
|
|
23
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
24
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
25
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
26
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
27
|
+
import com.flybits.concierge.Concierge
|
|
28
|
+
import com.flybits.concierge.ConciergeConstants
|
|
29
|
+
import com.flybits.concierge.ConciergeConstants.BROADCAST_CONCIERGE_EVENT
|
|
30
|
+
import com.flybits.concierge.ConciergeConstants.CONCIERGE_IDENTIFIER
|
|
31
|
+
import com.flybits.concierge.enums.ConciergeParams
|
|
32
|
+
import com.flybits.concierge.enums.Container
|
|
33
|
+
|
|
34
|
+
const val TAG_CONCIERGE_VIEW_MANAGER = "ConciergeViewManager"
|
|
35
|
+
|
|
36
|
+
class ConciergeViewManager(private val reactContext: ReactApplicationContext)
|
|
37
|
+
: ViewGroupManager<FrameLayout>(),
|
|
38
|
+
LifecycleEventListener {
|
|
39
|
+
private var propWidth: Int? = null
|
|
40
|
+
private var propHeight: Int? = null
|
|
41
|
+
private var broadcastReceiver: BroadcastReceiver? = null
|
|
42
|
+
private var actionLink: ActionLink? = null
|
|
43
|
+
|
|
44
|
+
companion object {
|
|
45
|
+
private const val REACT_CLASS = "ConciergeView"
|
|
46
|
+
private const val COMMAND_CREATE = 1
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override fun getName() = REACT_CLASS
|
|
50
|
+
|
|
51
|
+
override fun createViewInstance(reactContext: ThemedReactContext): FrameLayout {
|
|
52
|
+
reactContext.reactApplicationContext.addLifecycleEventListener(this)
|
|
53
|
+
return FrameLayout(reactContext)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override fun getCommandsMap(): Map<String, Int> {
|
|
57
|
+
return mapOf("create" to COMMAND_CREATE)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override fun receiveCommand(
|
|
61
|
+
root: FrameLayout,
|
|
62
|
+
commandId: String,
|
|
63
|
+
args: ReadableArray?
|
|
64
|
+
) {
|
|
65
|
+
super.receiveCommand(root, commandId, args)
|
|
66
|
+
val reactNativeViewId = requireNotNull(args).getInt(0)
|
|
67
|
+
val style = args.getMap(1)
|
|
68
|
+
val action = args.getMap(2)
|
|
69
|
+
when (commandId.toInt()) {
|
|
70
|
+
COMMAND_CREATE -> createFragment(root, reactNativeViewId)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private fun createFragment(root: FrameLayout, reactNativeViewId: Int) {
|
|
75
|
+
val parentView = root.findViewById<ViewGroup>(reactNativeViewId)
|
|
76
|
+
setupLayout(parentView)
|
|
77
|
+
|
|
78
|
+
var conciergeFragment: Fragment? =
|
|
79
|
+
if (actionLink != null && actionLink!!.actionableLink != null) {
|
|
80
|
+
actionLink!!.actionableLink?.let {
|
|
81
|
+
Concierge.handleActionableLink(context = reactContext, actionableLink = it,
|
|
82
|
+
conciergeTheme = null,
|
|
83
|
+
requestEvents = ConciergeParams.RequestEvents(), conciergeOptions = arrayListOf())
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
Concierge.fragment(
|
|
87
|
+
reactContext,
|
|
88
|
+
Container.Configured,
|
|
89
|
+
arrayListOf(), arrayListOf())
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
val activity = reactContext.currentActivity as FragmentActivity
|
|
93
|
+
|
|
94
|
+
conciergeFragment?.let {
|
|
95
|
+
activity.supportFragmentManager
|
|
96
|
+
.beginTransaction()
|
|
97
|
+
.replace(reactNativeViewId, conciergeFragment!!, reactNativeViewId.toString())
|
|
98
|
+
.commit()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private fun setupLayout(view: View) {
|
|
103
|
+
Choreographer.getInstance().postFrameCallback(object : Choreographer.FrameCallback {
|
|
104
|
+
override fun doFrame(frameTimeNanos: Long) {
|
|
105
|
+
manuallyLayoutChildren(view)
|
|
106
|
+
view.viewTreeObserver.dispatchOnGlobalLayout()
|
|
107
|
+
Choreographer.getInstance().postFrameCallback(this)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private fun manuallyLayoutChildren(view: View) {
|
|
113
|
+
val width: Int
|
|
114
|
+
val height: Int
|
|
115
|
+
if (propWidth != null && propHeight != null) {
|
|
116
|
+
width = requireNotNull(propWidth)
|
|
117
|
+
height = requireNotNull(propHeight)
|
|
118
|
+
} else {
|
|
119
|
+
width = view.measuredWidth
|
|
120
|
+
height = view.measuredHeight
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
view.measure(
|
|
124
|
+
View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
125
|
+
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY))
|
|
126
|
+
|
|
127
|
+
view.layout(0, 0, width, height)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override fun onHostResume() {
|
|
131
|
+
if (broadcastReceiver == null) {
|
|
132
|
+
broadcastReceiver = object : BroadcastReceiver() {
|
|
133
|
+
override fun onReceive(context: Context?, intent: Intent?) {
|
|
134
|
+
val identifier = intent?.extras?.getString(CONCIERGE_IDENTIFIER)
|
|
135
|
+
|
|
136
|
+
val actionableLink = intent?.extras?.getString(ConciergeConstants.ACTIONABLE_URL)
|
|
137
|
+
actionableLink?.let {
|
|
138
|
+
val uri = Uri.parse(actionableLink)
|
|
139
|
+
val action = uri.scheme
|
|
140
|
+
|
|
141
|
+
val params = Arguments.createMap().apply {
|
|
142
|
+
putString("type", "conciergeAction")
|
|
143
|
+
val p = Arguments.createMap().apply {
|
|
144
|
+
uri.queryParameterNames.forEach { key ->
|
|
145
|
+
putString(key, uri.getQueryParameter(key))
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
val actionable = Arguments.createMap().apply {
|
|
149
|
+
putString("action", action)
|
|
150
|
+
putMap("params", p)
|
|
151
|
+
putString("identifier", identifier)
|
|
152
|
+
}
|
|
153
|
+
putMap("actionableLink", actionable)
|
|
154
|
+
}
|
|
155
|
+
val body = Arguments.createMap().apply {
|
|
156
|
+
putMap("body", params)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
reactContext
|
|
160
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
161
|
+
.emit("Concierge-Event", body)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
val analyticsType = intent?.extras?.getString(ConciergeConstants.ANALYTICS_TYPE)
|
|
165
|
+
val contentData: HashMap<String, Any>? = intent?.extras?.getSerializable(ConciergeConstants.CONTENT_DATA) as HashMap<String, Any>?
|
|
166
|
+
val contentInfo: HashMap<String, String>? = intent?.extras?.getSerializable(ConciergeConstants.CONTENT_INFO) as HashMap<String, String>?
|
|
167
|
+
analyticsType?.let {
|
|
168
|
+
val cData = Arguments.createMap().apply {
|
|
169
|
+
contentData?.let { data ->
|
|
170
|
+
for ((k, v) in data) {
|
|
171
|
+
putString(k, v.toString())
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
val cInfo = Arguments.createMap().apply {
|
|
176
|
+
contentInfo?.let { info ->
|
|
177
|
+
for ((k, v) in info) {
|
|
178
|
+
putString(k, v.toString())
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
val params = Arguments.createMap().apply {
|
|
183
|
+
putString("type", "conciergeAnalytics")
|
|
184
|
+
putString("analyticsType", analyticsType)
|
|
185
|
+
putMap("contentData", cData)
|
|
186
|
+
putMap("contentInfo", cInfo)
|
|
187
|
+
}
|
|
188
|
+
val body = Arguments.createMap().apply {
|
|
189
|
+
putMap("body", params)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
reactContext
|
|
193
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
194
|
+
.emit("Concierge-Event", body)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
val hasContent = intent?.extras?.getString(ConciergeConstants.HAS_CONTENT)
|
|
198
|
+
hasContent?.let {
|
|
199
|
+
val params = Arguments.createMap().apply {
|
|
200
|
+
putString("type", "conciergeContentFetch")
|
|
201
|
+
putBoolean("hasContent", hasContent.toBoolean())
|
|
202
|
+
putString("identifier", identifier)
|
|
203
|
+
}
|
|
204
|
+
val body = Arguments.createMap().apply {
|
|
205
|
+
putMap("body", params)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
reactContext
|
|
209
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
210
|
+
.emit("Concierge-Event", body)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
val intentFilter = IntentFilter()
|
|
216
|
+
intentFilter.addAction(BROADCAST_CONCIERGE_EVENT)
|
|
217
|
+
@SuppressLint("WrongConstant")
|
|
218
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
219
|
+
ContextCompat.registerReceiver(reactContext, broadcastReceiver, intentFilter, ContextCompat.RECEIVER_NOT_EXPORTED)
|
|
220
|
+
} else {
|
|
221
|
+
LocalBroadcastManager.getInstance(reactContext)
|
|
222
|
+
.registerReceiver(broadcastReceiver as BroadcastReceiver, intentFilter)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
override fun onHostPause() {
|
|
227
|
+
if (broadcastReceiver != null) {
|
|
228
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
229
|
+
reactContext.unregisterReceiver(broadcastReceiver)
|
|
230
|
+
} else {
|
|
231
|
+
LocalBroadcastManager.getInstance(reactContext).unregisterReceiver(broadcastReceiver as BroadcastReceiver)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
override fun onHostDestroy() {
|
|
237
|
+
// No-op
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@ReactProp(name = "style")
|
|
241
|
+
fun setStyle(view: FrameLayout, value: ReadableMap) {
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
@ReactProp(name = "actionlink")
|
|
245
|
+
fun setActionLink(view: FrameLayout, value: ReadableMap) {
|
|
246
|
+
val action = if (value.getString("action") != null) "${value.getString("action")}://" else "concierge://"
|
|
247
|
+
val identifier = value.getString("identifier")
|
|
248
|
+
val params = if (value.getMap("params") != null) value.getMap("params")!!.toHashMap() else hashMapOf()
|
|
249
|
+
val linkBuilder = StringBuilder()
|
|
250
|
+
linkBuilder.append("$action?")
|
|
251
|
+
for ((k, v) in params) {
|
|
252
|
+
linkBuilder.append("$k=${v}")
|
|
253
|
+
linkBuilder.append("&")
|
|
254
|
+
}
|
|
255
|
+
val link = linkBuilder.toString().dropLast(1)
|
|
256
|
+
actionLink = ActionLink(Uri.parse(link), identifier)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@ReactProp(name = "zoneReferenceIDs")
|
|
260
|
+
fun setZoneReferenceIds(view: FrameLayout, value: ReadableMap) {
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
@ReactProp(name = "onActionEvent")
|
|
264
|
+
fun setOnActionEvent(view: FrameLayout, value: Boolean) {
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
@ReactProp(name = "onContentArrived")
|
|
268
|
+
fun setOnContentArrived(view: FrameLayout, value: Boolean) {
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
@ReactProp(name = "onConciergeChange")
|
|
272
|
+
fun setOnConciergeChange(view: FrameLayout, value: Boolean) {
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
@ReactProp(name = "onAnalyticsEvent")
|
|
276
|
+
fun setOnAnalyticsEvent(view: FrameLayout, value: Boolean) {
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
internal data class ActionLink(val actionableLink: Uri?, val identifier: String?)
|
|
280
|
+
}
|