Current Situtation
I work on an iOS SDK containing several UIViewControllers
that can be customized through a delegate function passing a String
as the identifier and getting a customized CALayer
. With that, the host application can customize how the SDK looks.
This is an example:
extension ViewController: NINChatSessionDelegate {
func ninchat(_ session: NINChatSession, overrideLayer assetKey: CALayerConstant) -> CALayer? {
switch assetKey {
case .ninchatPrimaryButton:
let layer = CALayer()
layer.backgroundColor = UIColor.gray.cgColor
layer.masksToBounds = true
layer.cornerRadius = 20.0
return layer
default:
return nil
}
}
Problem
Nowadays, I'm trying to migrate the code to SwiftUI and Combine. But I cannot find a way to offer host applications to inject their own attributes. As far as I have understood, a ViewModifier
struct is used to apply custom attributes to one or multiple View(s)
in SwiftUI. However, I could not yet find a way to inject them to the SDK because a ViewModifier
protocol has Self or associated type requirements
I appreciate any helps and guides.