+ // Scroll to the new tab position if moving to the new tab.
+ if (moveToTab)
+ tabLayout.post {
+ tabLayout.setScrollPosition(newTabPosition, 0F, false, false)
+ }
+
+ // Show the app bar if it is at the bottom of the screen and the new tab is taking focus.
+ if (bottomAppBar && moveToTab && appBarLayout.translationY != 0f) {
+ // Animate the bottom app bar onto the screen.
+ objectAnimator = ObjectAnimator.ofFloat(appBarLayout, "translationY", 0f)
+
+ // Make it so.
+ objectAnimator.start()
+ }
+ } else { // The new page is not ready.
+ // Create a new tab handler.
+ val newTabHandler = Handler(Looper.getMainLooper())
+
+ // Create a new tab runnable.
+ val newTabRunnable = Runnable {
+ // Create the new tab.
+ addNewTab(newTabPosition, moveToTab)
+ }
+
+ // Try adding the new tab again after 50 milliseconds.
+ newTabHandler.postDelayed(newTabRunnable, 50)