-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding a possibility to NibLoadable custom views to be automatically loaded when referenced from another XIB or Storyboard #105
base: main
Are you sure you want to change the base?
Conversation
…loaded when referenced from another XIB or Storyboard
Hello and thanks for the PR. Can you explain in more details the pros and cons of this approach? If I understand your explanation correctly:
In the current way the library is working, we never do view substitutions – so we never risk breaking existing constraints or outlets. What we do instead is:
Using So in my humble optioning, this has a potential to break way more things for the user of the lib in unexpected ways (constraints but also inspector properties – IBInspectable or not –, outlets and collections…), leading to more obscure bugs and support tickets for people trying that route, while the only "benefit" is to allow you not to set the File's Owner in your XIB to the appropriate class, so I don't feel it's worth the trouble it might bring. |
Hi, thanks for getting back to this PR.
That's exactly what I am trying to avoid -> to have more flattened view hierarchy, if one is using a lot of reusable XIBs, simple screens can get quite heavy.
You misunderstood me. It does not break constraints created in the XIB of this All constraints/iboutlet/ibinspectable properties in XIB of this
True, but at the same time the owner-loading mechanism is also not designed for that.
"you create this object in your code and pass it to the nib-loading code" -> exactly the case for In my opinion, this drawback is insignificant. There is another advantage of this approach, it makes possible to use `NibLoadable` in both other XIBs and in code, without creating this artificial FIle Owner. More over this approach is totally opt-in, as one just need to manually add: override func awakeAfter(using coder: NSCoder) -> Any? {
return self.awakeAfterUsingSurrogate()
} in the desired view. But that's all, it is that simple. |
Hi
I would like to add a possibility for
NibLoadable
views to be automatically loaded when referenced from another XIB or Storyboard.The current approach in Reusable is to only use
NibOwnerLoadable
views, but it produces an unnecessary nesting due to the fact that the file owner is also a UIView. I think theNibOwnerLoadable
makes more sense for things like UIViewController where UIViewController is not the UIView itself but in fact the owner of a UIView instance.In general this is the difference in layout:
MyCustomView
isNibLoadable
and its content: UILabel and UIView are not nested in the UIView as in the case ofMyCustomWidget
(NibOwnerLoadable
)Minor drawack is that it will break any constraints created in the XIB or Storyboard where
NibLoadable
view is referenced from (constraint outlets inNibLoadable
XIB are safe and work just fine!). This is because the placeholder view in these other files is substituted with the real instance loaded from the XIB.So
NibLoadable
andNibOwnerLoadable
both have some pros and cons, but it would be great to use Reusable and have a choice :)