Skip to content
Merged
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
12 changes: 6 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ dependencies {
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation 'com.expofp:common:4.6.2'
implementation 'com.expofp:fplan:4.6.2'
implementation 'com.expofp:common:4.9.6'
implementation 'com.expofp:fplan:4.9.6'

implementation 'com.expofp:crowdconnected:4.6.2'
implementation 'net.crowdconnected.android.core:android-core:1.5.1'
implementation 'net.crowdconnected.android.ips:android-ips:1.5.1'
implementation 'net.crowdconnected.android.geo:android-geo:1.5.1'
implementation 'com.expofp:crowdconnected:4.9.6'
implementation 'net.crowdconnected.android.core:android-core:2.0.0'
implementation 'net.crowdconnected.android.ips:android-ips:2.0.0'
implementation 'net.crowdconnected.android.geo:android-geo:2.0.0'
}

28 changes: 28 additions & 0 deletions android/src/main/java/com/expofp/ExpofpModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.expofp

import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.Promise
import com.expofp.fplan.SharedFplanView
import com.expofp.fplan.models.Settings
import com.facebook.react.bridge.UiThreadUtil

class ExpofpModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
override fun getName() = "ExpofpModule"

@ReactMethod
fun preload(url: String, promise: Promise) {
try {
val context = this.reactApplicationContext.applicationContext
UiThreadUtil.runOnUiThread {
SharedFplanView.preload(url, Settings(), context)
}
promise.resolve(null)
} catch (e: Exception) {
promise.reject("PRELOAD_ERROR", e.message)
}
}
}
2 changes: 1 addition & 1 deletion android/src/main/java/com/expofp/ExpofpPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.facebook.react.uimanager.ViewManager

class ExpofpPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
return emptyList()
return listOf(ExpofpModule(reactContext)).toMutableList()
}

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
Expand Down
9 changes: 4 additions & 5 deletions android/src/main/java/com/expofp/ExpofpViewManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@ import com.expofp.common.GlobalLocationProvider
import com.expofp.crowdconnected.CrowdConnectedProvider
import com.expofp.crowdconnected.Mode
import com.expofp.crowdconnected.Settings
import com.expofp.fplan.FplanView
import com.expofp.fplan.SharedFplanView
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp


class ExpofpViewManager : SimpleViewManager<View>() {
private var reactContext: ThemedReactContext? = null

override fun getName() = "ExpofpView"

override fun createViewInstance(reactContext: ThemedReactContext): View {
this.reactContext = reactContext
var view = FplanView(reactContext)
var view = SharedFplanView(reactContext)

return view;
}

@ReactProp(name = "settings")
fun setSettings(view: FplanView, settingsMap: ReadableMap?) {
fun setSettings(view: SharedFplanView, settingsMap: ReadableMap?) {
settingsMap?.let {
var appKey = settingsMap.getString("appKey")
val token = settingsMap.getString("token")
Expand Down Expand Up @@ -64,7 +63,7 @@ class ExpofpViewManager : SimpleViewManager<View>() {
GlobalLocationProvider.init(locationProvider)
GlobalLocationProvider.start()
}
view.init(it.getString("url") ?: "", com.expofp.fplan.models.Settings().withGlobalLocationProvider());
view.load(it.getString("url") ?: "", com.expofp.fplan.models.Settings().withGlobalLocationProvider());
}
}
}
1 change: 1 addition & 0 deletions ios/ExpofpModule-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import <React/RCTBridgeModule.h>
6 changes: 6 additions & 0 deletions ios/ExpofpModule.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#import "React/RCTBridgeModule.h"

@interface RCT_EXTERN_MODULE(ExpofpModule, NSObject)
RCT_EXTERN_METHOD(preload:(NSString *)url resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
@end
16 changes: 16 additions & 0 deletions ios/ExpofpModule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ExpoFpFplan
import ExpoFpCommon
import Foundation

@objc(ExpofpModule)
class ExpofpModule: NSObject {

@objc static func requiresMainQueueSetup() -> Bool {
return false
}

@objc func preload(_ url: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
SharedFplanView.preload(url, settings: Settings())
resolve(nil)
}
}
9 changes: 2 additions & 7 deletions ios/ExpofpViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ class ExpoFPViewProxy: UIView {
if let appKey = settings["appKey"] as? String,
let token = settings["token"] as? String,
let secret = settings["secret"] as? String {
let ccSettings = Settings(
appKey,
token,
secret,
Mode.IPS_AND_GPS
);
let ccSettings = Settings(appKey: appKey, token: token, secret: secret, mode: Mode.IPS_AND_GPS)
if let onesignalUserId = settings["oneSignalUserId"] as? String {
ccSettings.addAlias("onesignal_user_id", onesignalUserId)
}
Expand Down Expand Up @@ -76,7 +71,7 @@ class ExpoFPDataStore: ObservableObject {
struct ExpoFP: View {
@EnvironmentObject var dataStore: ExpoFPDataStore

var fplanView = FplanView()
var fplanView = SharedFplanView()

@State private var loadedUrl: NSString? = nil

Expand Down
6 changes: 3 additions & 3 deletions react-native-expofp.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Pod::Spec.new do |s|
s.authors = package["author"]

s.platforms = { :ios => "15.0" }
s.source = { :git => "https://github.com/artieeg/react-native-expofp.git", :tag => "#{s.version}" }
s.source = { :git => "https://github.com/gitamego/react-native-expofp.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm,swift}"

s.dependency "ExpoFpFplan", "4.7.1"
s.dependency "ExpoFpCrowdConnected", "4.7.1"
s.dependency "ExpoFpFplan", "4.8.15"
s.dependency "ExpoFpCrowdConnected", "4.8.15"

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
Expand Down
31 changes: 28 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {
UIManager,
Platform,
type ViewStyle,
NativeModules,
TurboModuleRegistry,
TurboModule,
} from 'react-native';

const LINKING_ERROR =
Expand All @@ -15,11 +18,11 @@ type ExpofpProps = {
style: ViewStyle;
settings: {
url: string;
oneSignalUserId?: string,
appKey?: string
oneSignalUserId?: string;
appKey?: string;
token?: string;
secret?: string;
}
};
};

const ComponentName = 'ExpofpView';
Expand All @@ -30,3 +33,25 @@ export const ExpofpView =
: () => {
throw new Error(LINKING_ERROR);
};

interface ExpofpModule extends TurboModule {
preload(url: string): Promise<void>;
}

export const preload = async (url: string): Promise<void> => {
if (Platform.OS === 'ios') {
const Module = TurboModuleRegistry.get<ExpofpModule>('ExpofpModule');
if (!Module) {
throw new Error(LINKING_ERROR);
}
return Module.preload(url);
}
if (Platform.OS === 'android') {
const Module = NativeModules.ExpofpModule;
if (!Module) {
throw new Error(LINKING_ERROR);
}
return Module.preload(url);
}
throw new Error('Unsupported platform');
};