-
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.
Related: * `TODO:2023-03-30-20-13-10` - Impl: `UIWindow.windowID`.
- Loading branch information
1 parent
99c2903
commit 18159ac
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
ios/src_library/Helpers+Utilities/UIWindow+WindowMetadata.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,48 @@ | ||
// | ||
// UIWindow+WindowMetadata.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 3/30/23. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
fileprivate final class WindowMetadata { | ||
static var counterID = -1; | ||
|
||
let id: Int = { | ||
WindowMetadata.counterID += 1; | ||
return WindowMetadata.counterID; | ||
}(); | ||
|
||
let uuid = UUID(); | ||
}; | ||
|
||
|
||
public extension UIWindow { | ||
|
||
fileprivate static let windowMetadataMap = NSMapTable<UIWindow, WindowMetadata>( | ||
keyOptions: .weakMemory, | ||
valueOptions: .strongMemory | ||
); | ||
|
||
fileprivate var windowMetadata: WindowMetadata { | ||
if let windowMetadata = Self.windowMetadataMap.object(forKey: self) { | ||
return windowMetadata; | ||
}; | ||
|
||
let windowMetadata = WindowMetadata(); | ||
Self.windowMetadataMap.setObject(windowMetadata, forKey: self); | ||
|
||
return windowMetadata; | ||
}; | ||
|
||
var windowID: Int { | ||
self.windowMetadata.id; | ||
}; | ||
|
||
var windowUUID: UUID { | ||
self.windowMetadata.uuid; | ||
}; | ||
}; |