Initial reactions implementation

This commit is contained in:
Ali
2021-11-30 22:18:02 +04:00
parent 37e869f8f2
commit 3dc4efbfcb
60 changed files with 2808 additions and 1702 deletions

View File

@@ -104,6 +104,10 @@ public protocol _TypeErasedComponent {
func _isEqual(to other: _TypeErasedComponent) -> Bool
}
public protocol ComponentTaggedView: UIView {
func matches(tag: Any) -> Bool
}
public protocol Component: _TypeErasedComponent, Equatable {
associatedtype EnvironmentType = Empty
associatedtype View: UIView = UIView

View File

@@ -1,6 +1,22 @@
import Foundation
import UIKit
private func findTaggedViewImpl(view: UIView, tag: Any) -> UIView? {
if let view = view as? ComponentTaggedView {
if view.matches(tag: tag) {
return view
}
}
for subview in view.subviews {
if let result = findTaggedViewImpl(view: subview, tag: tag) {
return result
}
}
return nil
}
public final class ComponentHostView<EnvironmentType>: UIView {
private var currentComponent: AnyComponent<EnvironmentType>?
private var currentContainerSize: CGSize?
@@ -78,4 +94,12 @@ public final class ComponentHostView<EnvironmentType>: UIView {
let result = super.hitTest(point, with: event)
return result
}
public func findTaggedView(tag: Any) -> UIView? {
guard let componentView = self.componentView else {
return nil
}
return findTaggedViewImpl(view: componentView, tag: tag)
}
}