Skip to content

Commit

Permalink
Fixed ViewPager bug when rotating device (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Droppers committed Mar 15, 2020
1 parent 54524a6 commit dfdb5c2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Download the app showcasing the examples: [demo.apk](./media/demo.apk)
Add the following dependency to your <b>build.gradle</b>:

```gradle
implementation 'nl.joery.animatedbottombar:library:1.0.2'
implementation 'nl.joery.animatedbottombar:library:1.0.4'
```

Define `AnimatedBottomBar` in your XML layout with custom attributes.
Expand Down
16 changes: 8 additions & 8 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

ext {
bintrayRepo = "AnimatedBottomBar"
bintrayName = "nl.joery.animatedbottombar"
bintrayRepo = 'AnimatedBottomBar'
bintrayName = 'nl.joery.animatedbottombar'

publishedGroupId = 'nl.joery.animatedbottombar'
libraryName = 'library'
libraryName = 'l1ibrary'
artifact = 'library'

libraryVersion = '1.0.2'
libraryVersion = '1.0.4'
libraryDescription = 'A customizable and easy to use BottomBar navigation view with sleek animations.'
siteUrl = 'https://github.com/Droppers/AnimatedBottomBar'
gitUrl = 'https://github.com/Droppers/AnimatedBottomBar.git'
Expand All @@ -23,7 +23,7 @@ ext {

licenseName = 'The MIT License'
licenseUrl = 'https://github.com/Droppers/AnimatedBottomBar/blob/master/LICENSE'
allLicenses = ["MIT"]
allLicenses = ['MIT']
}

android {
Expand All @@ -35,8 +35,8 @@ android {
versionCode 1
versionName libraryVersion

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
consumerProguardFiles 'consumer-rules.pro'
}

buildTypes {
Expand All @@ -55,7 +55,7 @@ android {
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ class AnimatedBottomBar @JvmOverloads constructor(
* @param title The title of the tab.
* @param id A unique identifier of a tab.
*/
fun createTab(icon: Drawable, title: String, @IdRes id: Int = -1): Tab {
fun createTab(icon: Drawable?, title: String, @IdRes id: Int = -1): Tab {
if (icon == null) {
throw IllegalArgumentException("Icon drawable cannot be null.")
}
return Tab(icon, title, id)
}

Expand All @@ -271,7 +274,7 @@ class AnimatedBottomBar @JvmOverloads constructor(
*/
fun createTab(@DrawableRes iconRes: Int, title: String, @IdRes id: Int = -1): Tab {
val icon = ContextCompat.getDrawable(context, iconRes)
return createTab(icon!!, title, id)
return createTab(icon, title, id)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat

@ColorInt
fun Context.getColorResCompat(@AttrRes id: Int): Int {
internal fun Context.getColorResCompat(@AttrRes id: Int): Int {
return ContextCompat.getColor(this, getResourceId(id))
}

@ColorInt
fun Context.getTextColor(@AttrRes id: Int): Int {
internal fun Context.getTextColor(@AttrRes id: Int): Int {
val typedValue = TypedValue()
theme.resolveAttribute(id, typedValue, true)
val arr = obtainStyledAttributes(
Expand All @@ -26,11 +26,11 @@ fun Context.getTextColor(@AttrRes id: Int): Int {
return color
}

fun Context.getResourceId(id: Int): Int {
internal fun Context.getResourceId(id: Int): Int {
val resolvedAttr = TypedValue()
theme.resolveAttribute(id, resolvedAttr, true)
return resolvedAttr.run { if (resourceId != 0) resourceId else data }
}

val Int.px: Int
internal val Int.px: Int
get() = (this * Resources.getSystem().displayMetrics.density).toInt()
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ internal class TabIndicator(
return
}

if (!animate || lastIndex == -1) {
val newView = parent.getChildAt(newIndex)
if (!animate || lastIndex == -1 || newView == null) {
parent.postInvalidate()
return
}

lastSelectedIndex = lastIndex

val newView = parent.getChildAt(newIndex)
animator = ValueAnimator.ofFloat(currentLeft, newView.left.toFloat()).apply {
duration = bottomBar.tabStyle.animationDuration.toLong()
interpolator = bottomBar.tabStyle.animationInterpolator
Expand Down
Binary file added media/demo.apk
Binary file not shown.

0 comments on commit dfdb5c2

Please sign in to comment.