-
Notifications
You must be signed in to change notification settings - Fork 28
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
Pipe Blueprint's environment through during layout and measurement by creating an environment of our own #225
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High level thoughts/questions:
- Do we need the env to also exist/get passed through in the
ListableUI
types? If you think it's useful I'm fine with it, but I'm not sure I see the utility of it? - If the answer to ^ is no, we don't need it, I don't think we should add a
ListEnvironment
type at all, and just pipe through the BP environment. We can add keys and use the BP environment to pass stuff down inBlueprintUILists
I guess I'm not seeing how we'd get the Blueprint
The key part being there's an inner extra layer of blueprint views whose lifetime is not known or controlled by users of the |
(I do wonder if there's some way that we can / need to solve this more generally in blueprint at some point – eg this will also break for any nested BP views in Market itself; which is not good for when we let people inject custom content, or we want to leverage the environment ourselves... But that's a whole thing) |
section += TestItemContent(wasCalled: callback) | ||
} | ||
}.adaptedEnvironment { env in | ||
env[TestingKey.self] = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth an XCTAssertTrue(env[TestingKey.self])
somewhere at the end of the test (similar to TestHeaderContent
and TestItemContent
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify what you mean here? I think this would only be testing Blueprint itself; since this is just a normal element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just missed that it was a plain mock element the first time around and asking from a place of "if we set a state in a test, should we assert that it was set anywhere?"
} else { | ||
self.content = nil | ||
} | ||
} | ||
} | ||
|
||
var reuseCache : ReusableViewCache? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when would the reuseCache be nil— if we init something instead of dequeuing it?
if so, something like precondition(reuseCache != nil, "must dequeue a Supplementary Container View")
might make it clearer. definitely a nit, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because these are UICollectionReusableView
; the init method is called by UICollectionView – you can't customize it. Thus, using IUOs to make things explode if these properties haven't been injected, without having to unwrap it at every callsite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an inline comment to clarify this
/// } | ||
/// } | ||
/// ``` | ||
public struct ListEnvironment { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe something like
public typealias ListEnvironment = BlueprintUI.Environment
public typealias ListEnvironmentKey = BlueprintUI.EnvironmentKey
for now? so you own the type but don't have to rebuild the world until you have a use-case to do so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ListableUI
itself doesnt depend on BlueprintUI
, so, can't do that.
My naive expectation was that So if the tree was
so instead of the EnvironmentReader at level 5 fizzling out at level 3 because it found a UIView, it would keep traversing the view hierarchy to see if any parent was a view backed by a BlueprintElement and could provide an Environment to use but on second thought, going up the tree is likely messy implementation (e.g.: would it require the description view to have a back reference to any ElementContent in case it holds an Environment?) and definitely not as nice as explicitly propagating state down the tree |
Yeah, this – and there's different layout and measurement passes; so you can't just pass it down or "reach up" to find the current status easily. |
Yeah, that makes a lot of sense, thanks. I was thinking that the Environment is more independent of the layout/measurement passes so it might be okay. But now that you mention it, I can definitely see people wanting to store per-view information in an environment and propagate it down (e.g. the view size influencing size classes as you get further down the tree is super believable) |
… creating an environment of our own
d90d494
to
213f94f
Compare
@kylebshr any more thoughts here? I can set up some time to run thorough why this is needed (I think?) which might be easier than going back and forth here |
I didn't realize at first that it had to pass through |
This PR updates
List
to ensure that we passBlueprintUI.Environment
through to the inner blueprint views within each item and header/footer within the list. This is done by writingBlueprintUI.Environment
into our ownListEnvironment
– which is now piped through to each item and header/footer within the list, and then, we reach this into environment and pull out the bp environment withinBlueprintItemContent
andBlueprintHeaderFooterContent
to continue to pass the values down.