Skip to content

feat: configurable entry point #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2022
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
2 changes: 1 addition & 1 deletion ReactNativePortals.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Pod::Spec.new do |s|
s.source_files = "ios/**/*.{h,m,mm,swift}"

s.dependency "React-Core"
s.dependency "IonicPortals", "~> 0.6.1"
s.dependency "IonicPortals", "~> 0.6.3"
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.annotations.ReactProp
import com.getcapacitor.CapConfig
import com.getcapacitor.JSObject
import com.getcapacitor.Plugin
import io.ionic.liveupdates.LiveUpdate
Expand All @@ -19,16 +20,12 @@ import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

internal class PortalManagerModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
override fun getName() = "IONPortalManager"

@ReactMethod
fun register(key: String) {
PortalManager.register(key)
}
internal object RNPortalManager {
private val manager = PortalManager
internal var indexMap: MutableMap<String, String> = mutableMapOf()
lateinit var reactApplicationContext: ReactApplicationContext

@ReactMethod
fun register(key: String) = manager.register(key)
fun addPortal(map: ReadableMap) {
val name = map.getString("name") ?: return
val portalBuilder = PortalBuilder(name)
Expand All @@ -40,6 +37,9 @@ internal class PortalManagerModule(reactContext: ReactApplicationContext) :
?.toHashMap()
?.let(portalBuilder::setInitialContext)

map.getString("index")
?.let { indexMap[name] = "/$it" }

map.getArray("androidPlugins")
?.toArrayList()
?.mapNotNull { it as? String }
Expand Down Expand Up @@ -72,6 +72,25 @@ internal class PortalManagerModule(reactContext: ReactApplicationContext) :
}
}

internal class PortalManagerModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
override fun getName() = "IONPortalManager"

init {
RNPortalManager.reactApplicationContext = reactContext
}

@ReactMethod
fun register(key: String) {
RNPortalManager.register(key)
}

@ReactMethod
fun addPortal(map: ReadableMap) {
RNPortalManager.addPortal(map)
}
}

internal class PortalsPubSubModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
override fun getName() = "IONPortalPubSub"
Expand Down Expand Up @@ -213,6 +232,15 @@ internal class PortalViewManager(private val context: ReactApplicationContext) :
setupLayout(parentView)

val portalFragment = PortalFragment(portal)

val configBuilder = CapConfig.Builder(context)
.setInitialFocus(false)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I looked in ionic-portals-android, I saw that this was being set if there was no CapConfig defined. @carlpoole Do you think this should be added as a configuration to the Portal as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, but maybe we should look at the config as a whole and see if we should make some things more configurable on the Portal instead of reaching into the config to have to do some things


RNPortalManager.indexMap[portal.name]
?.let(configBuilder::setStartPath)

portalFragment.setConfig(configBuilder.create())

viewState.initialContext?.let(portalFragment::setInitialContext)

viewState.fragment = portalFragment
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ target 'ReactNativePortals' do
use_frameworks!
use_react_native!(:path => config["reactNativePath"])
# Pods for ReactNativePortals
pod 'IonicPortals', '~> 0.6.1'
pod 'IonicPortals', '~> 0.6.3'
end

24 changes: 12 additions & 12 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PODS:
- boost-for-react-native (1.63.0)
- Capacitor (3.6.0):
- Capacitor (3.7.0):
- CapacitorCordova
- CapacitorCordova (3.6.0)
- CapacitorCordova (3.7.0)
- DoubleConversion (1.1.6)
- FBLazyVector (0.63.4)
- FBReactNativeSpec (0.63.4):
Expand All @@ -22,10 +22,10 @@ PODS:
- DoubleConversion
- glog
- glog (0.3.5)
- IonicLiveUpdates (0.1.1)
- IonicPortals (0.6.1):
- Capacitor (~> 3.5)
- IonicLiveUpdates (~> 0.1.0)
- IonicLiveUpdates (0.1.3)
- IonicPortals (0.6.3):
- Capacitor (~> 3.7)
- IonicLiveUpdates (~> 0.1.2)
- RCTRequired (0.63.4)
- RCTTypeSafety (0.63.4):
- FBLazyVector (= 0.63.4)
Expand Down Expand Up @@ -260,7 +260,7 @@ DEPENDENCIES:
- FBReactNativeSpec (from `../node_modules/react-native/Libraries/FBReactNativeSpec`)
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
- IonicPortals (~> 0.6.1)
- IonicPortals (~> 0.6.3)
- RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`)
- RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`)
- React (from `../node_modules/react-native/`)
Expand Down Expand Up @@ -349,15 +349,15 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
Capacitor: 28d6f7c3b02858b0696c98d27527ffb1ac8aba8f
CapacitorCordova: 23b4def1cd6a8c463074916376f511d7446d683e
Capacitor: 747a1e47077e8f82abf2209867c440d7366ad68c
CapacitorCordova: e6b42a8e8d5986c1eb8f02ac0be205fafc32ac33
DoubleConversion: cde416483dac037923206447da6e1454df403714
FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e
FBReactNativeSpec: f2c97f2529dd79c083355182cc158c9f98f4bd6e
Folly: b73c3869541e86821df3c387eb0af5f65addfab4
glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
IonicLiveUpdates: 5fb89c6faed266d083691e64f33710211edb3839
IonicPortals: 17b9ee9ae513fc3906b062bdd0b7492db94e38ce
IonicLiveUpdates: 91481e88b9a9a9bc02aecc589ed4bcfd658c4854
IonicPortals: 752f740cfaf84fafd45c0d9ab7b06c6b2a281993
RCTRequired: 082f10cd3f905d6c124597fd1c14f6f2655ff65e
RCTTypeSafety: 8c9c544ecbf20337d069e4ae7fd9a377aadf504b
React: b0a957a2c44da4113b0c4c9853d8387f8e64e615
Expand All @@ -380,6 +380,6 @@ SPEC CHECKSUMS:
ReactCommon: 73d79c7039f473b76db6ff7c6b159c478acbbb3b
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6

PODFILE CHECKSUM: 67d6b2cc79c25d2c4dcf32d6e3c6d6e6defffdb1
PODFILE CHECKSUM: d6df5af67dbc83914b551c00dd0fbfac38c74589

COCOAPODS: 1.11.2
1 change: 1 addition & 0 deletions ios/ReactNativePortals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ extension Portal {
self.init(
name: name,
startDir: dict["startDir"] as? String,
index: dict["index"] as? String ?? "index.html",
initialContext: JSTypes.coerceDictionaryToJSObject(dict["initialContext"] as? [String: Any]) ?? [:],
liveUpdateConfig: (dict["liveUpdate"] as? [String: Any]).flatMap(LiveUpdate.init)
)
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface Portal {
name: string;
androidPlugins?: string[];
startDir?: string;
index?: string;
initialContext?: {
[key: string]: any;
};
Expand Down