From 3be6a7758cdb9dbd6ba609717a482fdf9f44ad33 Mon Sep 17 00:00:00 2001 From: goweii Date: Sat, 17 Jun 2023 22:59:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(layer-dialog):=20DialogLayer=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=85=A8=E5=B1=8F=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DialogLayer支持全屏模式,可以通过setFitInsets方法打开。 Closes #13 --- .../per/goweii/layer/dialog/ktx/DialogLayer.kt | 4 ++++ .../per/goweii/layer/dialog/DialogLayer.java | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/layer-dialog-ktx/src/main/java/per/goweii/layer/dialog/ktx/DialogLayer.kt b/layer-dialog-ktx/src/main/java/per/goweii/layer/dialog/ktx/DialogLayer.kt index 2cb7e58..bd9e5ff 100644 --- a/layer-dialog-ktx/src/main/java/per/goweii/layer/dialog/ktx/DialogLayer.kt +++ b/layer-dialog-ktx/src/main/java/per/goweii/layer/dialog/ktx/DialogLayer.kt @@ -36,6 +36,10 @@ fun T.avoidStatusBar(enable: Boolean) = this.apply { this.setAvoidStatusBar(enable) } +fun T.fitInsets(fitInsets: Boolean) = this.apply { + this.setFitInsets(fitInsets) +} + fun T.gravity(gravity: Int) = this.apply { this.setGravity(gravity) } diff --git a/layer-dialog/src/main/java/per/goweii/layer/dialog/DialogLayer.java b/layer-dialog/src/main/java/per/goweii/layer/dialog/DialogLayer.java index bdf1e6f..f2f3d96 100644 --- a/layer-dialog/src/main/java/per/goweii/layer/dialog/DialogLayer.java +++ b/layer-dialog/src/main/java/per/goweii/layer/dialog/DialogLayer.java @@ -160,7 +160,7 @@ protected View onCreateChild(@NonNull LayoutInflater inflater, @NonNull ViewGrou return container; } - @NonNull + @Nullable protected View onCreateBackground(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) { if (getConfig().mBackgroundView != null) { ViewGroup backgroundParent = (ViewGroup) getConfig().mBackgroundView.getParent(); @@ -346,7 +346,9 @@ protected FrameLayout.LayoutParams generateContentDefaultLayoutParams() { @Override protected void fitDecorInsets(@NonNull Rect insets) { - Utils.setViewPadding(getViewHolder().getContentWrapper(), insets); + if (getConfig().mFitInsets) { + Utils.setViewPadding(getViewHolder().getContentWrapper(), insets); + } if (getConfig().mAvoidStatusBar) { int paddingTop = getViewHolder().getContentWrapper().getPaddingTop(); int statusBarHeight = Utils.getStatusBarHeightIfVisible(getActivity()); @@ -618,6 +620,17 @@ public DialogLayer setBackgroundColorRes(@ColorRes int colorRes) { return this; } + /** + * 设置是否避开页面内边距 + * + * @param fitInsets 设置是否避开页面内边距 + */ + @NonNull + public DialogLayer setFitInsets(boolean fitInsets) { + getConfig().mFitInsets = fitInsets; + return this; + } + /** * 设置避开状态栏 * @@ -845,6 +858,7 @@ protected static class Config extends DecorLayer.Config { protected boolean mCancelableOnTouchOutside = true; + protected boolean mFitInsets = true; protected boolean mAvoidStatusBar = false; protected int mGravity = Gravity.NO_GRAVITY;