Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions android/src/main/java/com/siftreactnative/SiftReactNativeModule.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.siftreactnative

import com.facebook.react.bridge.LifecycleEventListener
import android.text.TextUtils
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.Promise
import com.facebook.react.turbomodule.core.interfaces.TurboModule
import com.facebook.react.bridge.LifecycleEventListener
import siftscience.android.Sift
import android.text.TextUtils

class SiftReactNativeModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext),
LifecycleEventListener {
class SiftReactNativeModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext),
TurboModule,
LifecycleEventListener {

private var siftConfig: Sift.Config? = null

init {
Expand All @@ -21,21 +24,25 @@ class SiftReactNativeModule(reactContext: ReactApplicationContext) : ReactContex
}

@ReactMethod
fun setSiftConfig(accountId: String, beaconKey: String, disallowCollectingLocationData: Boolean,
serverUrlFormat: String) {
fun setSiftConfig(
accountId: String,
beaconKey: String,
disallowCollectingLocationData: Boolean,
serverUrlFormat: String
) {
siftConfig = if (TextUtils.isEmpty(serverUrlFormat)) {
Sift.Config.Builder()
.withAccountId(accountId)
.withBeaconKey(beaconKey)
.withDisallowLocationCollection(disallowCollectingLocationData)
.build()
Sift.Config.Builder()
.withAccountId(accountId)
.withBeaconKey(beaconKey)
.withDisallowLocationCollection(disallowCollectingLocationData)
.build()
} else {
Sift.Config.Builder()
.withAccountId(accountId)
.withBeaconKey(beaconKey)
.withDisallowLocationCollection(disallowCollectingLocationData)
.withServerUrlFormat(serverUrlFormat)
.build()
Sift.Config.Builder()
.withAccountId(accountId)
.withBeaconKey(beaconKey)
.withDisallowLocationCollection(disallowCollectingLocationData)
.withServerUrlFormat(serverUrlFormat)
.build()
}
Sift.open(reactApplicationContext, siftConfig)
Sift.collect()
Expand All @@ -44,7 +51,7 @@ class SiftReactNativeModule(reactContext: ReactApplicationContext) : ReactContex
@ReactMethod
fun setUserId(userId: String) {
if (!TextUtils.isEmpty(userId)) {
Sift.setUserId(userId)
Sift.setUserId(userId)
}
}

Expand Down Expand Up @@ -74,6 +81,4 @@ class SiftReactNativeModule(reactContext: ReactApplicationContext) : ReactContex
override fun onHostDestroy() {
Sift.close()
}


}
}
37 changes: 27 additions & 10 deletions android/src/main/java/com/siftreactnative/SiftReactNativePackage.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
package com.siftreactnative

import java.util.Arrays
import java.util.Collections

import com.facebook.react.ReactPackage
import com.facebook.react.TurboReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager
import com.facebook.react.bridge.JavaScriptModule
import com.facebook.react.module.model.ReactModuleInfo
import com.facebook.react.module.model.ReactModuleInfoProvider

class SiftReactNativePackage : TurboReactPackage() {
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
return when (name) {
"SiftReactNative" -> SiftReactNativeModule(reactContext)
else -> null
}
}

class SiftReactNativePackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
return Arrays.asList<NativeModule>(SiftReactNativeModule(reactContext))
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
return ReactModuleInfoProvider {
mapOf(
"SiftReactNative" to ReactModuleInfo(
"SiftReactNative",
"SiftReactNative",
/* canOverrideExistingModule */ false,
/* needsEagerInit */ false,
/* hasConstants */ true,
/* isCxxModule */ false,
/* isTurboModule */ true
)
)
}
}

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
return emptyList<ViewManager<*, *>>()
return emptyList()
}
}
}
6 changes: 0 additions & 6 deletions example/.buckconfig

This file was deleted.

2 changes: 0 additions & 2 deletions example/.bundle/config

This file was deleted.

4 changes: 0 additions & 4 deletions example/.eslintrc.js

This file was deleted.

66 changes: 0 additions & 66 deletions example/.flowconfig

This file was deleted.

64 changes: 0 additions & 64 deletions example/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions example/.prettierrc.js

This file was deleted.

1 change: 0 additions & 1 deletion example/.ruby-version

This file was deleted.

1 change: 0 additions & 1 deletion example/.watchmanconfig

This file was deleted.

Loading