@ionic/portals-react-native 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -99,7 +99,32 @@ int main(int argc, char *argv[])
99
99
  ```
100
100
 
101
101
  ##### Podfile
102
- Because many of the Ionic Portals dependencies are comprised of Swift code and have custom module maps, you will need to add `use_frameworks!` to your iOS Podfile and remove `use_flipper!()`
102
+ There are two methods you may use to ensure Portals can integrate into your React Native application: a custom `pre_install` hook or adding `use_frameworks!` to your Podfile. Only one of these approaches is needed to ensure that Capacitor is compiled as a dynamic framework.
103
+
104
+ **pre_install**
105
+
106
+ Using the `pre_install` hook allows you to keep all the other React Native dependencies as static frameworks:
107
+ ```ruby
108
+ # These frameworks are required to be dynamic.
109
+ dynamic_frameworks = ['Capacitor', 'CapacitorCordova']
110
+
111
+ pre_install do |installer|
112
+ installer.pod_targets.each do |pod|
113
+ if dynamic_frameworks.include?(pod.name)
114
+ def pod.static_framework?
115
+ false
116
+ end
117
+ def pod.build_type
118
+ Pod::BuildType.dynamic_framework
119
+ end
120
+ end
121
+ end
122
+ end
123
+ ```
124
+
125
+ **use_frameworks**
126
+
127
+ Alternative to the `pre_install` hook, you can add `use_frameworks!` to your Podfile application target. Using this approach requires removing `use_flipper!()` from the Podfile.
103
128
 
104
129
  ### Communicating between React Native and Web
105
130
  One of the key features of Ionic Portals for React Native is facilitating communication between the web and React Native layers of your application.
@@ -74,6 +74,7 @@ class PortalViewManager: RCTViewManager {
74
74
 
75
75
  class PortalView: UIView {
76
76
  private var webView: PortalUIView?
77
+ private var _initialContext: [String: JSValue]?
77
78
 
78
79
  @objc var name: String? {
79
80
  get {
@@ -88,21 +89,22 @@ class PortalView: UIView {
88
89
  }
89
90
 
90
91
  @objc var initialContext: [String: Any]? {
91
- get {
92
- guard let portal = _portal else { return nil }
93
- return portal.initialContext
94
- }
95
-
92
+ get { _initialContext }
96
93
  set {
97
- guard let name = name else { return }
98
- _portal = PortalManager.getPortal(named: name)
99
- _portal?.initialContext = JSTypes.coerceDictionaryToJSObject(newValue) ?? [:]
94
+ _initialContext = JSTypes.coerceDictionaryToJSObject(newValue)
95
+ // If the Portal is already present then we need to set the initialContext so it's the `didSet` property observer is fired
96
+ _portal?.initialContext = _initialContext ?? [:]
100
97
  }
101
98
  }
102
99
 
103
100
  private var _portal: Portal? {
104
101
  didSet {
105
- guard let portal = _portal else { return }
102
+ guard var portal = _portal else { return }
103
+
104
+ if let initialContext = _initialContext {
105
+ portal.initialContext = initialContext
106
+ }
107
+
106
108
  DispatchQueue.main.async { [weak self] in
107
109
  guard let self = self else { return }
108
110
  self.webView?.removeFromSuperview()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ionic/portals-react-native",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Ionic Portals for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",