Skip to content

Commit

Permalink
Add an ability to specify the bottom sheet view container top & botto…
Browse files Browse the repository at this point in the history
…m padding
  • Loading branch information
arthur3486 committed Aug 27, 2019
1 parent c6b7b3e commit 1b3c4a3
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 35 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ android {
lintOptions {
abortOnError false
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}

dependencies {
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":11,"versionName":"1.0.2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":13,"versionName":"1.1.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
5 changes: 5 additions & 0 deletions bottomsheets-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ android {
lintOptions {
abortOnError false
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ private void initBottomSheet() {
mBottomSheetView = new FrameLayout(getContext());
mBottomSheetView.setLayoutParams(generateDefaultLayoutParams());
mBottomSheetView.setBackground(createBottomSheetBackgroundDrawable());
mBottomSheetView.setPadding(
mBottomSheetView.getPaddingLeft(),
((int) mConfig.getExtraPaddingTop()),
mBottomSheetView.getPaddingRight(),
((int) mConfig.getExtraPaddingBottom())
);

// Creating the actual sheet content view
final View createdSheetView = Preconditions.checkNonNull(onCreateSheetContentView(getContext()));
Expand Down Expand Up @@ -347,38 +353,42 @@ public final void dismiss(boolean animate) {


private void postViewShowingAction(final boolean animate) {
postPendingViewManagementAction(new Runnable() {
@Override
public void run() {
if(animate) {
if(!State.EXPANDED.equals(mState) && !State.EXPANDING.equals(mState)) {
setUiState(State.COLLAPSED);
animateStateTransition(State.EXPANDING);
}
} else {
setUiState(mState = State.EXPANDED);
}
postPendingViewManagementAction(() -> expandSheet(animate));
}




private void expandSheet(final boolean animate) {
if(animate) {
if(!State.EXPANDED.equals(mState) && !State.EXPANDING.equals(mState)) {
setUiState(State.COLLAPSED);
animateStateTransition(State.EXPANDING);
}
});
} else {
setUiState(mState = State.EXPANDED);
}
}




private void postViewDismissingAction(final boolean animate) {
postPendingViewManagementAction(new Runnable() {
@Override
public void run() {
if(animate) {
if(!State.COLLAPSED.equals(mState) && !State.COLLAPSING.equals(mState)) {
animateStateTransition(State.COLLAPSING);
}
} else {
removeFromContainer();
setUiState(mState = State.COLLAPSED);
}
postPendingViewManagementAction(() -> collapseSheet(animate));
}




private void collapseSheet(final boolean animate) {
if(animate) {
if(!State.COLLAPSED.equals(mState) && !State.COLLAPSING.equals(mState)) {
animateStateTransition(State.COLLAPSING);
}
});
} else {
removeFromContainer();
setUiState(mState = State.COLLAPSED);
}
}


Expand Down Expand Up @@ -430,15 +440,12 @@ private void animateStateTransition(final State state) {

// creating and starting a brand-new one
mAnimator = ValueAnimator.ofFloat(startValue, endValue);
mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
final float animatedValue = (Float) valueAnimator.getAnimatedValue();
final float newY = (startY + (animatedValue * (endY - startY)));
mAnimator.addUpdateListener(valueAnimator -> {
final float animatedValue = (Float) valueAnimator.getAnimatedValue();
final float newY = (startY + (animatedValue * (endY - startY)));

mBottomSheetView.setY(newY);
setBackgroundAlpha(animatedValue);
}
mBottomSheetView.setY(newY);
setBackgroundAlpha(animatedValue);
});
mAnimator.addListener(new AnimatorListenerAdapter() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ public interface BaseConfig {
*/
float getTopGapSize();

/**
* Retrieves the extra padding top.
*
* @return the extra padding from the top.
*/
float getExtraPaddingTop();

/**
* Retrieves the extra padding bottom.
*
* @return the extra padding from the bottom.
*/
float getExtraPaddingBottom();

/**
* Retrieves the sheet's maximum width.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ public interface BaseConfigBuilder<BT extends BaseConfigBuilder, CT> extends Bui
@NonNull
BT maxSheetWidth(float maxWidth);

/**
* Sets the top padding that will be added to the bottom sheet view container.
*
* @param extraPaddingTop the extra padding from the top
* @return the current instance of the configuration builder (for chaining purposes)
*/
@NonNull
BT extraPaddingTop(float extraPaddingTop);

/**
* Sets the bottom padding that will be added to the bottom sheet view container.
*
* @param extraPaddingBottom the extra padding from the bottom
* @return the current instance of the configuration builder (for chaining purposes)
*/
@NonNull
BT extraPaddingBottom(float extraPaddingBottom);

/**
* Sets the background dimming color.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public final class Config implements BaseConfig {
private final float sheetCornerRadius;
private final float maxSheetWidth;
private final float topGapSize;
private final float extraPaddingTop;
private final float extraPaddingBottom;

private final int dimColor;
private final int sheetBackgroundColor;
Expand All @@ -57,6 +59,8 @@ private Config(Builder builder) {
this.sheetCornerRadius = builder.sheetCornerRadius;
this.maxSheetWidth = builder.maxSheetWidth;
this.topGapSize = builder.topGapSize;
this.extraPaddingTop = builder.extraPaddingTop;
this.extraPaddingBottom = builder.extraPaddingBottom;
this.dimColor = builder.dimColor;
this.sheetBackgroundColor = builder.sheetBackgroundColor;
this.animationDuration = builder.animationDuration;
Expand Down Expand Up @@ -91,6 +95,22 @@ public final float getTopGapSize() {



@Override
public final float getExtraPaddingTop() {
return this.extraPaddingTop;
}




@Override
public final float getExtraPaddingBottom() {
return this.extraPaddingBottom;
}




@Override
public final float getMaxSheetWidth() {
return this.maxSheetWidth;
Expand Down Expand Up @@ -146,6 +166,8 @@ public static final class Builder implements BaseConfigBuilder<Builder, BaseConf
private float sheetCornerRadius;
private float maxSheetWidth;
private float topGapSize;
private float extraPaddingTop;
private float extraPaddingBottom;

private int dimColor;
private int sheetBackgroundColor;
Expand All @@ -164,6 +186,8 @@ public Builder(@NonNull Context context) {
this.dimAmount = DEFAULT_DIM_AMOUNT;
this.sheetCornerRadius = resources.getDimension(R.dimen.bottom_sheet_sheet_corner_radius);
this.topGapSize = 0;
this.extraPaddingTop = 0;
this.extraPaddingBottom = 0;
this.maxSheetWidth = resources.getDimension(R.dimen.bottom_sheet_max_sheet_width);
this.dimColor = ContextCompat.getColor(context, R.color.bottom_sheet_dim_color);
this.sheetBackgroundColor = ContextCompat.getColor(context, R.color.bottom_sheet_background_color);
Expand Down Expand Up @@ -194,6 +218,22 @@ public final Builder topGapSize(float topGapSize) {
}


@NonNull
@Override
public final Builder extraPaddingTop(float extraPaddingTop) {
this.extraPaddingTop = extraPaddingTop;
return this;
}


@NonNull
@Override
public final Builder extraPaddingBottom(float extraPaddingBottom) {
this.extraPaddingBottom = extraPaddingBottom;
return this;
}


@NonNull
public final Builder maxSheetWidth(float maxWidth) {
this.maxSheetWidth = maxWidth;
Expand Down
5 changes: 5 additions & 0 deletions bottomsheets-ktx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ android {
lintOptions {
abortOnError false
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
5 changes: 5 additions & 0 deletions bottomsheets-sheets/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ android {
lintOptions {
abortOnError false
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public final class Config implements ActionPickerConfig {
private final float maxSheetWidth;
private final float topGapSize;
private final float titleTextSize;
private final float extraPaddingTop;
private final float extraPaddingBottom;

private final int dimColor;
private final int sheetBackgroundColor;
Expand All @@ -62,6 +64,8 @@ private Config(Builder builder) {
this.sheetCornerRadius = builder.sheetCornerRadius;
this.maxSheetWidth = builder.maxSheetWidth;
this.topGapSize = builder.topGapSize;
this.extraPaddingTop = builder.extraPaddingTop;
this.extraPaddingBottom = builder.extraPaddingBottom;
this.titleTextSize = builder.titleTextSize;
this.dimColor = builder.dimColor;
this.sheetBackgroundColor = builder.sheetBackgroundColor;
Expand Down Expand Up @@ -124,6 +128,22 @@ public final float getTopGapSize() {



@Override
public final float getExtraPaddingTop() {
return this.extraPaddingTop;
}




@Override
public final float getExtraPaddingBottom() {
return this.extraPaddingBottom;
}




@Override
public final float getMaxSheetWidth() {
return this.maxSheetWidth;
Expand Down Expand Up @@ -180,6 +200,8 @@ public static final class Builder implements ActionPickerConfigBuilder<Builder,
private float maxSheetWidth;
private float topGapSize;
private float titleTextSize;
private float extraPaddingTop;
private float extraPaddingBottom;

private int dimColor;
private int sheetBackgroundColor;
Expand All @@ -201,6 +223,8 @@ public Builder(@NonNull Context context) {
this.dimAmount = DEFAULT_DIM_AMOUNT;
this.sheetCornerRadius = resources.getDimension(R.dimen.bottom_sheet_sheet_corner_radius);
this.topGapSize = 0;
this.extraPaddingTop = 0;
this.extraPaddingBottom = 0;
this.titleTextSize = resources.getDimensionPixelSize(R.dimen.action_picker_bottom_sheet_title_text_size);
this.maxSheetWidth = resources.getDimension(R.dimen.bottom_sheet_max_sheet_width);
this.dimColor = ContextCompat.getColor(context, R.color.bottom_sheet_dim_color);
Expand Down Expand Up @@ -255,6 +279,22 @@ public final Builder topGapSize(float topGapSize) {
}


@NonNull
@Override
public final Builder extraPaddingTop(float extraPaddingTop) {
this.extraPaddingTop = extraPaddingTop;
return this;
}


@NonNull
@Override
public final Builder extraPaddingBottom(float extraPaddingBottom) {
this.extraPaddingBottom = extraPaddingBottom;
return this;
}


@NonNull
public final Builder maxSheetWidth(float maxWidth) {
this.maxSheetWidth = maxWidth;
Expand Down
4 changes: 2 additions & 2 deletions common/constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ project.ext {
releaseRepoName = "maven"
releaseUserOrg = "arthurlabs"
releaseGroupId = "com.arthurivanets.bottomsheet"
releaseVersion = "1.1.1"
releaseVersionCode = 13
releaseVersion = "1.1.2"
releaseVersionCode = 14
releaseWebsite = "https://github.com/arthur3486/bottomsheet"
releaseLicense = ["Apache-2.0"]

Expand Down

0 comments on commit 1b3c4a3

Please sign in to comment.