Skip to content

Commit e96c92c

Browse files
authored
fix: stretch tabbar to full width (#122)
* fix: stretch tabbar to full width * fix: use try,catch for loading images
1 parent 5591868 commit e96c92c

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

android/src/main/java/com/rcttabview/RCTTabView.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,22 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
158158
itemRippleColor = color
159159
}
160160

161-
private fun getDrawable(imageSource: ImageSource): Drawable {
162-
// TODO: Check if this can be done using some built-in React Native class
163-
val imageRequest = ImageRequestBuilder.newBuilderWithSource(imageSource.uri).build()
164-
val dataSource = Fresco.getImagePipeline().fetchDecodedImage(imageRequest, context)
165-
val result = DataSources.waitForFinalResult(dataSource) as CloseableReference<CloseableBitmap>
166-
val bitmap = result.get().underlyingBitmap
167-
168-
CloseableReference.closeSafely(result)
169-
dataSource.close()
161+
private fun getDrawable(imageSource: ImageSource): Drawable? {
162+
try {
163+
val imageRequest = ImageRequestBuilder.newBuilderWithSource(imageSource.uri).build()
164+
val dataSource = Fresco.getImagePipeline().fetchDecodedImage(imageRequest, context)
165+
val result = DataSources.waitForFinalResult(dataSource) as CloseableReference<CloseableBitmap>
166+
val bitmap = result.get().underlyingBitmap
167+
168+
CloseableReference.closeSafely(result)
169+
dataSource.close()
170+
171+
return BitmapDrawable(resources, bitmap)
172+
} catch (_: Exception) {
173+
// Asset doesn't exist
174+
}
170175

171-
return BitmapDrawable(resources, bitmap)
176+
return null
172177
}
173178

174179
override fun onDetachedFromWindow() {

android/src/newarch/RCTTabViewManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ class RCTTabViewManager(context: ReactApplicationContext) :
121121
val bottomInset = RCTTabViewImpl.getNavigationBarInset(contextInner)
122122

123123
return YogaMeasureOutput.make(
124-
toDIPFromPixel(view.measuredWidth.toFloat()),
124+
// TabBar should always stretch to the width of the screen.
125+
toDIPFromPixel(width),
125126
toDIPFromPixel(view.measuredHeight.toFloat() + bottomInset)
126127
)
127128
}

android/src/oldarch/RCTTabViewManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ class RCTTabViewManager(context: ReactApplicationContext) : SimpleViewManager<Re
143143

144144
val navigationBarInset = RCTTabViewImpl.getNavigationBarInset(themedContext)
145145
tabView.measure(spec, spec)
146-
this.mWidth = tabView.measuredWidth
146+
// TabBar should always stretch to the width of the screen.
147+
this.mWidth = width.toInt()
147148
this.mHeight = tabView.measuredHeight + navigationBarInset
148149
this.mMeasured = true
149150

0 commit comments

Comments
 (0)