-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Extract types in `ios/src_library/React Native/RNIIdentifiable/RNIIdentifiable` into their own files.
- Loading branch information
1 parent
737047b
commit ef64878
Showing
3 changed files
with
91 additions
and
74 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
ios/src_library/React Native/RNIIdentifiable/RNIIdentifiable+Default.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// RNIIdentifiable+Default.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 4/27/23. | ||
// | ||
|
||
import Foundation | ||
|
||
extension RNIIdentifiable { | ||
public static var synthesizedIdPrefix: String { | ||
String(describing: Self.self) + "-"; | ||
}; | ||
|
||
public var synthesizedIdentifier: RNIObjectIdentifier { | ||
if let identifier = self.metadata { | ||
return identifier; | ||
}; | ||
|
||
let identifier = RNIObjectIdentifier(type: Self.self); | ||
self.metadata = identifier; | ||
|
||
return identifier; | ||
}; | ||
|
||
public var synthesizedID: Int { | ||
self.synthesizedIdentifier.id; | ||
}; | ||
|
||
public var synthesizedStringID: String { | ||
Self.synthesizedIdPrefix + "\(self.synthesizedID)"; | ||
}; | ||
|
||
public var synthesizedUUID: UUID { | ||
self.synthesizedIdentifier.uuid; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
ios/src_library/React Native/RNIIdentifiable/RNIObjectIdentifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// RNIObjectIdentifier.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 4/27/23. | ||
// | ||
|
||
import Foundation | ||
|
||
fileprivate class Counter { | ||
static var typeToCounterMap: Dictionary<String, Int> = [:]; | ||
|
||
static func getTypeString(ofType _type: Any) -> String { | ||
return String(describing: type(of: _type)); | ||
}; | ||
|
||
static func set(forType type: Any, counter: Int) { | ||
let typeString = Self.getTypeString(ofType: type); | ||
Self.typeToCounterMap[typeString] = counter; | ||
}; | ||
|
||
static func set(forType typeString: String, counter: Int) { | ||
Self.typeToCounterMap[typeString] = counter; | ||
}; | ||
|
||
static func get(forType type: Any) -> Int { | ||
let typeString = Self.getTypeString(ofType: type); | ||
|
||
guard let counter = Self.typeToCounterMap[typeString] else { | ||
Self.set(forType: typeString, counter: -1); | ||
return -1; | ||
}; | ||
|
||
return counter; | ||
}; | ||
|
||
static func getAndIncrement(forType type: Any) -> Int { | ||
let prevCount = Self.get(forType: type); | ||
let nextCount = prevCount + 1; | ||
|
||
Self.set(forType: type, counter: nextCount); | ||
return nextCount; | ||
}; | ||
}; | ||
|
||
public final class RNIObjectIdentifier { | ||
|
||
public let id: Int; | ||
public let uuid = UUID(); | ||
|
||
public init(type: Any) { | ||
self.id = Counter.getAndIncrement(forType: type); | ||
}; | ||
}; |