Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
fixed bug in NavigationBarItems (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusribeirozup authored Apr 28, 2020
1 parent 179386f commit 2032234
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal class ScreenViewRenderer(
navigationBar: NavigationBar
) {
context.configureSupportActionBar()
toolbarManager.configureToolbar(context, navigationBar)
toolbarManager.configureNavigationBarForScreen(context, navigationBar)
toolbarManager.configureToolbar(context, navigationBar)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ internal class ToolbarManager(private val actionExecutor: ActionExecutor = Actio
navigationBar: NavigationBar
) {
context.getToolbar().apply {
removeAllViews()
visibility = View.VISIBLE
menu.clear()
configToolbarStyle(context, this, navigationBar)
Expand Down Expand Up @@ -91,6 +90,7 @@ internal class ToolbarManager(private val actionExecutor: ActionExecutor = Actio
R.styleable.BeagleToolbarStyle_titleTextAppearance, 0
)
if (typedArray.getBoolean(R.styleable.BeagleToolbarStyle_centerTitle, false)) {
removePreviousToolbarTitle(toolbar)
toolbar.addView(generateCenterTitle(context, navigationBar, textAppearance, toolbar))
} else {
toolbar.title = navigationBar.title
Expand All @@ -108,26 +108,32 @@ internal class ToolbarManager(private val actionExecutor: ActionExecutor = Actio
}
}

private fun removePreviousToolbarTitle(toolbar: Toolbar) {
val centeredTitle = toolbar.findViewById<TextView>(R.id.beagle_toolbar_text)
toolbar.removeView(centeredTitle)
}

private fun generateCenterTitle(
context: Context,
navigationBar: NavigationBar,
textAppearance: Int,
toolbar: Toolbar
) = TextView(context).apply {
val params = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
).apply {
gravity = Gravity.CENTER
}
layoutParams = params
text = navigationBar.title
if (textAppearance != 0) {
TextViewCompat.setTextAppearance(this, textAppearance)
}
toolbar.contentInsetStartWithNavigation = 0
toolbar.setContentInsetsAbsolute(0, 0)
id = R.id.beagle_toolbar_text
val params = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
).apply {
gravity = Gravity.CENTER
}
layoutParams = params
text = navigationBar.title
if (textAppearance != 0) {
TextViewCompat.setTextAppearance(this, textAppearance)
}
toolbar.contentInsetStartWithNavigation = 0
toolbar.setContentInsetsAbsolute(0, 0)
}

private fun configToolbarItems(
context: Context,
Expand Down
3 changes: 1 addition & 2 deletions android/beagle/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
-->

<resources>
<item name="beagle_content" type="id" />
<item name="beagle_toolbar" type="id" />
<item name="beagle_toolbar_text" type="id" />
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ class ScreenViewRendererTest : BaseTest() {

//THEN
verifyOrder {
toolbarManager.configureToolbar(context, navigationBar)
toolbarManager.configureNavigationBarForScreen(context, navigationBar)
toolbarManager.configureToolbar(context, navigationBar)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.impl.annotations.RelaxedMockK
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.slot
import io.mockk.spyk
Expand Down Expand Up @@ -193,7 +194,6 @@ class ToolbarManagerTest : BaseTest() {

// THEN
assertEquals(View.VISIBLE, toolbar.visibility)
verify(exactly = once()) { toolbar.removeAllViews() }
verify(exactly = once()) { menu.clear() }
verify(exactly = navigationBarItems.size) { menu.add(Menu.NONE, 0, Menu.NONE, "Stub") }
verify(exactly = navigationBarItems.size) { menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ScreenController(
fun getNavigationBarImage() = this.sampleNavigationBarService.navigationBarWithImageAsItem()

@Get(NAVIGATION_TYPE_ENDPOINT)
fun getSampleNavigationTypeControlller() = this.sampleNavigationTypeService.createNavigationTypeView()
fun getSampleNavigationTypeController() = this.sampleNavigationTypeService.createNavigationTypeView()

@Get(REPRESENTATION_NAVIGATION_TYPE_STEP2_ENDPOINT)
fun getNavigationStep2() = this.sampleNavigationTypeService.step2()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ScreenController(
fun getSampleFormView() = this.sampleFormService.createFormView()

@GetMapping(SCREEN_LAZY_COMPONENT_ENDPOINT )
fun getSampleLazyComponentConroller() = this.sampleLazyComponentService.createLazyComponent()
fun getSampleLazyComponentController() = this.sampleLazyComponentService.createLazyComponent()

@GetMapping(SCREEN_NAVIGATION_BAR_ENDPOINT)
fun getSampleNavigationBarController() =
Expand All @@ -155,7 +155,7 @@ class ScreenController(
fun getNavigationBarImage() = this.sampleNavigationBarService.navigationBarWithImageAsItem()

@GetMapping(NAVIGATION_TYPE_ENDPOINT)
fun getSampleNavigationTypeControlller() =
fun getSampleNavigationTypeController() =
this.sampleNavigationTypeService.createNavigationTypeView()

@GetMapping(REPRESENTATION_NAVIGATION_TYPE_STEP2_ENDPOINT)
Expand Down

0 comments on commit 2032234

Please sign in to comment.