Skip to content

Commit

Permalink
Add the Window Inset Change handling mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur3486 committed Apr 4, 2020
1 parent 4de5164 commit 0afe3f8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
13 changes: 13 additions & 0 deletions app/src/main/java/com/arthurivanets/demo/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.arthurivanets.demo.ui

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.arthurivanets.bottomsheets.BottomSheet
import com.arthurivanets.bottomsheets.ktx.actionPickerConfig
Expand Down Expand Up @@ -47,6 +48,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
init()
enableFullScreenMode()
}


Expand Down Expand Up @@ -77,6 +79,17 @@ class MainActivity : AppCompatActivity() {
}


private fun enableFullScreenMode() {
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
)
}


private fun showCustomBottomSheet() {
dismissBottomSheet()

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.animation.Interpolator;
import android.widget.FrameLayout;

Expand Down Expand Up @@ -101,6 +102,7 @@ private void init(Activity hostActivity) {
initContainer(hostActivity);
initResources(hostActivity);
initBottomSheet();
requestWindowInsetsWhenAttached();
}


Expand Down Expand Up @@ -174,6 +176,41 @@ private void initBottomSheet() {
}


@Override
public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
mBottomSheetView.setPadding(
mBottomSheetView.getPaddingLeft(),
mBottomSheetView.getPaddingTop(),
mBottomSheetView.getPaddingRight(),
(int) (insets.getSystemWindowInsetBottom() + mConfig.getExtraPaddingBottom())
);

return insets;
}


private void requestWindowInsetsWhenAttached() {
if(isAttachedToWindow()) {
requestApplyInsets();
} else {
addOnAttachStateChangeListener(new OnAttachStateChangeListener() {

@Override
public void onViewAttachedToWindow(View view) {
removeOnAttachStateChangeListener(this);
requestApplyInsets();
}

@Override
public void onViewDetachedFromWindow(View view) {
// do nothing
}

});
}
}


@Override
protected final LayoutParams generateDefaultLayoutParams() {
final LayoutParams layoutParams = new LayoutParams(
Expand Down
6 changes: 3 additions & 3 deletions common/constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
project.ext {
compileSdk = 29
targetSdk = 29
minSdk = 18
minSdk = 21

supportLibraryVersion = "1.1.0"
recyclerViewVersion = "1.1.0"
Expand All @@ -32,8 +32,8 @@ project.ext {
releaseRepoName = "maven"
releaseUserOrg = "arthurlabs"
releaseGroupId = "com.arthurivanets.bottomsheet"
releaseVersion = "1.1.4"
releaseVersionCode = 16
releaseVersion = "1.2.0"
releaseVersionCode = 17
releaseWebsite = "https://github.com/arthur3486/bottomsheet"
releaseLicense = ["Apache-2.0"]

Expand Down

0 comments on commit 0afe3f8

Please sign in to comment.