-
Notifications
You must be signed in to change notification settings - Fork 42
Add builder API for applying WindowInsets #62
Conversation
if (consumeSystemWindowInsets) { | ||
return insets.consumeSystemWindowInsets(); | ||
} else { | ||
return insets; | ||
} |
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 also considered surfacing this so callers can be more granular with how they consume insets. Consuming everything might be overkill, but it solves the initial issue described in the PR description.
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.
Yep, lgtm
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.
In that case, would it make sense to have OnApplyInsetsListener.onApplyInsets
return WindowInsetsCompat
? I could alternatively add a OnConsumeInsetsListener
interface.
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.
This also seems like it would make testing Builder.consumeSystemWindowInsets
a bit easier
public void applyToView(@NonNull View view) { | ||
build().setOnApplyInsetsListener(view); | ||
} |
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.
Not sure if this needs to be part of the builder
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 like this. I'd make the doc a bit clearer though. Something like:
Builds the
Insetter
instance and sets it as aOnApplyWindowInsetsListener
on [view].
Might also be worth returning the built Insetter
from the function too.
Looks great to me overall, a much nicer API for devs. Thank you 🙌 While looking through this some of the old API looks pretty crufty. While we're making big API changes, we may as well fix everything in one release 😃
|
* @see Insetter#setOnApplyInsetsListener(View) | ||
*/ | ||
@NonNull | ||
public Builder setOnApplyInsetsListener(OnApplyInsetsListener onApplyInsetsListener) { |
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.
@Nullable
param?
if (consumeSystemWindowInsets) { | ||
return insets.consumeSystemWindowInsets(); | ||
} else { | ||
return insets; | ||
} |
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.
Yep, lgtm
} | ||
} | ||
|
||
public static Builder builder() { |
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.
Needs doc
public void applyToView(@NonNull View view) { | ||
build().setOnApplyInsetsListener(view); | ||
} |
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 like this. I'd make the doc a bit clearer though. Something like:
Builds the
Insetter
instance and sets it as aOnApplyWindowInsetsListener
on [view].
Might also be worth returning the built Insetter
from the function too.
* @see Insetter#setOnApplyInsetsListener(View) | ||
*/ | ||
@NonNull | ||
public Builder consumeSystemWindowInsets(boolean consumeSystemWindowInsets) { |
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.
We should mention the default value of this in the doc.
Renaming to |
...src/main/java/dev/chrisbanes/insetter/widgets/constraintlayout/InsetterConstraintHelper.java
Outdated
Show resolved
Hide resolved
Really like how the bit field approach turned out 👍 |
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.
Really liking where this is heading. Just a few more tweaks and we can
public final class SideUtils { | ||
|
||
@Sides | ||
public static int create(boolean left, boolean top, boolean right, boolean bottom) { |
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.
Looks great. Maybe move this to the Side
class? Feels more fundamental than being in a utils class.
import android.view.View; | ||
import androidx.core.view.WindowInsetsCompat; | ||
import java.util.EnumSet; | ||
public final class Side { |
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.
Let's add a NONE = 0
too, rather than relying on 0
in the Insetter logic.
...src/main/java/dev/chrisbanes/insetter/widgets/constraintlayout/InsetterConstraintHelper.java
Outdated
Show resolved
Hide resolved
@@ -24,14 +24,6 @@ | |||
*/ | |||
public final class SideUtils { |
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.
Sorry, one last thing. We can now make this pkg-private.
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.
Perfect, thanks for the contribution!
For this most part, this just wraps the existing functionality with a builder API. Initial motivation for this was Insetter not providing a way to consume insets after applying them to a given
View
. A potential result is insets being applied a second time by childView
s/ViewGroup
s that automatically handle insets internally. I've restricted the scope of the original static utils where possible, and I also added a newconsumeSystemWindowInsets
attribute to the binding adapter.