Skip to content

Commit

Permalink
Release 0.7.0 (#56)
Browse files Browse the repository at this point in the history
* feat!: remove deprecated APIs
  • Loading branch information
Steven0351 authored Jun 26, 2024
1 parent dc56064 commit e792b4b
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class PortalViewManager(private val context: ReactApplicationContext) :
when (fragmentMap[viewGroup.id]) {
null -> fragmentMap[viewGroup.id] = PortalViewState(
fragment = null,
portal = RNPortalManager.getPortal(name) ?: RNPortalManager.createPortal(portal),
portal = RNPortalManager.createPortal(portal),
initialContext = portal.getMap("initialContext")?.toHashMap()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,11 @@ internal data class PortalPlugin(val androidClassPath: String, val iosClassName:

internal object RNPortalManager {
private val manager = PortalManager
@Deprecated("Will be removed in the next release.")
private val portals: ConcurrentHashMap<String, RNPortal> = ConcurrentHashMap()
private lateinit var reactApplicationContext: ReactApplicationContext
private var usesSecureLiveUpdates = false

fun register(key: String) = manager.register(key)

@Deprecated("Will be removed in the next release.")
fun addPortal(map: ReadableMap): RNPortal? {
val portal = createPortal(map) ?: return null
portals[portal.builder.name] = portal
return portal
}

fun createPortal(map: ReadableMap): RNPortal? {
val name = map.getString("name") ?: return null
val portalBuilder = PortalBuilder(name)
Expand Down Expand Up @@ -147,11 +138,6 @@ internal object RNPortalManager {
)
}

@Deprecated("Will be removed in the next release.")
fun getPortal(name: String): RNPortal? {
return portals[name]
}

fun enableSecureLiveUpdates(keyPath: String) {
LiveUpdateManager.secureLiveUpdatePEM = keyPath
usesSecureLiveUpdates = true
Expand Down Expand Up @@ -183,13 +169,6 @@ internal object RNPortalManager {
LiveUpdateManager.secureLiveUpdatePEM = it
usesSecureLiveUpdates = true
}

val portalJsonArray = configJson.getJSONArray("portals")

for (index in 0 until portalJsonArray.length()) {
val portalJson = portalJsonArray.getJSONObject(index)
addPortal(portalJson.toReactMap())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,6 @@ internal class PortalManagerModule(reactContext: ReactApplicationContext) :
promise.resolve(null)
}

@ReactMethod
fun addPortal(map: ReadableMap, promise: Promise) {
val portal = RNPortalManager.addPortal(map)
if (portal == null) {
promise.reject(null, "Invalid Portal configuration.")
} else {
promise.resolve(portal.toReadableMap())
}
}

@ReactMethod
fun addPortals(array: ReadableArray, promise: Promise) {
val portals = WritableNativeArray()

for (i in 0 until array.size()) {
val map = array.getMap(i)
val portal = RNPortalManager.addPortal(map) ?: continue
portals.pushMap(portal.toReadableMap())
}

promise.resolve(portals)
}

@ReactMethod
fun getPortal(name: String, promise: Promise) {
try {
val portal = RNPortalManager.getPortal(name)
promise.resolve(portal?.toReadableMap())
} catch (e: IllegalStateException) {
promise.reject(null, "Portal named $name not registered.")
}
}

@ReactMethod
fun enableSecureLiveUpdates(keyPath: String, promise: Promise) {
RNPortalManager.enableSecureLiveUpdates(keyPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,6 @@ import com.facebook.react.bridge.ReactMethod
internal class PortalWebVitalsModule(reactContext: ReactApplicationContext): ReactContextBaseJavaModule(reactContext) {
override fun getName() = "IONPortalsWebVitals"

private fun registerVital(portalName: String, vitalName: String) {
val portal = RNPortalManager.getPortal(portalName) ?: return
if (portal.vitals == null) {
portal.vitals = mutableListOf()
}
portal.vitals?.add(vitalName)
}

@ReactMethod
fun registerOnFirstContentfulPaint(portalName: String, promise: Promise) {
registerVital(portalName,"fcp")
promise.resolve(null)
}

@ReactMethod
fun registerOnFirstInputDelay(portalName: String, promise: Promise) {
registerVital(portalName,"fid")
promise.resolve(null)
}

@ReactMethod
fun registerOnTimeToFirstByte(portalName: String, promise: Promise) {
registerVital(portalName,"ttfb")
promise.resolve(null)
}

@ReactMethod
fun addListener(eventName: String) {
}
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ PODS:
- React-logger (= 0.74.2)
- React-perflogger (= 0.74.2)
- React-utils (= 0.74.2)
- ReactNativePortals (0.5.2):
- ReactNativePortals (0.6.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1435,10 +1435,10 @@ SPEC CHECKSUMS:
React-runtimescheduler: 56b642bf605ba5afa500d35790928fc1d51565ad
React-utils: 4476b7fcbbd95cfd002f3e778616155241d86e31
ReactCommon: ecad995f26e0d1e24061f60f4e5d74782f003f12
ReactNativePortals: 9bfdb3928c55e58ba22b21d99775aa3bb33c4df8
ReactNativePortals: 42f59afa6ed4119897d2dd7c9e5f66599c022684
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Yoga: ae3c32c514802d30f687a04a6a35b348506d411f

PODFILE CHECKSUM: ce82c2dd878c18eaa5b59018ea58e2e1c0876c21

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
12 changes: 2 additions & 10 deletions example/ios/PortalsReactNativeExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,7 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
OTHER_LDFLAGS = "$(inherited)";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down Expand Up @@ -684,11 +680,7 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
OTHER_LDFLAGS = "$(inherited)";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down
26 changes: 13 additions & 13 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ export default function App() {
<View style={styles.container}>
<PubSubLabel initialNumber={initialNumber} />
{/* {ready ? ( */}
<PortalView
portal={portal}
style={styles.portalView}
// webVitals={{
// firstContentfulPaint: (duration: number) =>
// console.log('firstContentfulPaint', duration),
// firstInputDelay: (duration: number) =>
// console.log('firstInputDelay', duration),
// timeToFirstByte: (duration: number) => {
// console.log('timeToFirstByte', duration);
// },
// }}
/>
<PortalView
portal={portal}
style={styles.portalView}
webVitals={{
firstContentfulPaint: (duration: number) =>
console.log('firstContentfulPaint', duration),
firstInputDelay: (duration: number) =>
console.log('firstInputDelay', duration),
timeToFirstByte: (duration: number) => {
console.log('timeToFirstByte', duration);
},
}}
/>
{/* ) : (
<></>
)} */}
Expand Down
33 changes: 33 additions & 0 deletions ios/AssetMap+Codable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// IonicPortals+Codable.swift
// ReactNativePortals
//
// Created by Trevor Lambert on 6/5/24.
// Copyright © 2024 Facebook. All rights reserved.
//

import Foundation
import IonicPortals

extension AssetMap: Encodable {
enum CodingKeys: String, CodingKey {
case startDir, virtualPath, name
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(startDir, forKey: .startDir)
try container.encode(virtualPath, forKey: .virtualPath)
try container.encode(name, forKey: .name)
}
}

extension AssetMap: Decodable {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let name = try container.decode(String.self, forKey: .name)
let startDir = try container.decodeIfPresent(String.self, forKey: .startDir) ?? ""
let virtualPath = try container.decodeIfPresent(String.self, forKey: .virtualPath)
self.init(name: name, virtualPath: virtualPath, startDir: startDir)
}
}
28 changes: 0 additions & 28 deletions ios/AssetMap+Dict.swift

This file was deleted.

77 changes: 0 additions & 77 deletions ios/IonicPortals+Codable.swift

This file was deleted.

3 changes: 0 additions & 3 deletions ios/PortalManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
@interface RCT_EXTERN_MODULE(IONPortalsReactNative, NSObject)
RCT_EXTERN_METHOD(register: (NSString *) key resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
RCT_EXTERN_METHOD(enableSecureLiveUpdates: (NSString *) publicKeyPath resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
RCT_EXTERN_METHOD(addPortal: (NSDictionary) portal resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
RCT_EXTERN_METHOD(addPortals: (NSArray) portals resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
RCT_EXTERN_METHOD(getPortal: (NSString *) name resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
RCT_EXTERN_METHOD(syncOne: (NSString *) appId resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
RCT_EXTERN_METHOD(syncSome: (NSArray) appIds resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
RCT_EXTERN_METHOD(syncAll: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
Expand Down
26 changes: 9 additions & 17 deletions ios/PortalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,20 @@ class PortalView: UIView {
}

set {
guard let portalDict = newValue,
let name = portalDict["name"] as? String
else { return }

guard let portalDict = newValue else { return }

var portal: Portal

if var deprecatedPortal = PortalsReactNative.getPortal(named: name) {
if let initialContext = portalDict["initialContext"] as? [String: Any] {
deprecatedPortal.initialContext = JSTypes.coerceDictionaryToJSObject(initialContext) ?? [:]
}
portal = deprecatedPortal
} else {
do {
let jsObject = JSTypes.coerceDictionaryToJSObject(portalDict) ?? [:]
do {
portal = try Portal.decode(from: jsObject, with: JSValueDecoder())
} catch {
print(error.localizedDescription)
return
}
portal = try Portal.decode(from: jsObject, with: JSValueDecoder())
} catch {
print(error.localizedDescription)
return
}

if portal.usesWebVitals {
var vitalsPlugin = WebVitalsPlugin { portalName, duration in
let vitalsPlugin = WebVitalsPlugin { portalName, duration in
IonicPortals.PortalsPubSub
.shared
.publish(
Expand Down
Loading

0 comments on commit e792b4b

Please sign in to comment.