bluelinelabs / bluelinelabs/Conductor

RouterPagerAdapter ChildPageController bundle args are always empty

Open
#520 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.9k
Forks
338
PR merge metrics
No merged PRs in 30d

Description

Hello,
I have a problem with the bundleConstructor of my ChildController.
I have some parameters from ParentController. (TabViewController) and i can reach them when the constructor is called from TabViewController like;

val page = TabViewPageController(bundle)
router.setRoot(RouterTransaction.with(page))

But i can not reach them when the bundleConstructor is called from RouterTransaction

RouterTransaction(@NonNull Bundle bundle) {
controller = Controller.newInstance(bundle.getBundle(KEY_VIEW_CONTROLLER_BUNDLE));
pushControllerChangeHandler = ControllerChangeHandler.fromBundle(bundle.getBundle(KEY_PUSH_TRANSITION));
popControllerChangeHandler = ControllerChangeHandler.fromBundle(bundle.getBundle(KEY_POP_TRANSITION));
tag = bundle.getString(KEY_TAG);
transactionIndex = bundle.getInt(KEY_INDEX);
attachedToRouter = bundle.getBoolean(KEY_ATTACHED_TO_ROUTER);
}

When the newInstance method of ConductorController called, i see that my bundle is empty.
The code is below;
So; do you have any suggestions?
What am i doing wrong?
Thank you.

//PagerController

class TabViewController(args: Bundle) : BaseController() {
private val pagerAdapter: RouterPagerAdapter
private val headers = args.getIntArray("headers")
private val contents = args.getIntArray("contents")
private val headerTitle = args.getString("title")

init {
pagerAdapter = object : RouterPagerAdapter(this) {
override fun configureRouter(router: Router, position: Int) {
if (!router.hasRootController()) {
val bundle = Bundle()
bundle.putInt("TabViewPageController.index", position)
bundle.putIntArray("TabViewPageController.contents", contents)
val page = TabViewPageController(bundle)
router.setRoot(RouterTransaction.with(page))
}
}

override fun getCount(): Int {
return headers.size
}

override fun getPageTitle(position: Int): CharSequence? {
return context.getString(headers[position])
}
}
}

override val layoutId: Int
get() = R.layout.controller_tab_view

override val title: String
get() = headerTitle

override val header: FieldHeaderFormBinding
get() = binding.header

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
val v = super.onCreateView(inflater, container)
binding.viewPager.adapter = pagerAdapter
binding.tabLayout.setupWithViewPager(binding.viewPager)
binding.tabLayout.setSelectedTabIndicatorColor(Color.WHITE)
return v
}

override fun onDestroyView(view: View) {
if (!activity!!.isChangingConfigurations) {
binding.viewPager.adapter = null
}
binding.tabLayout.setupWithViewPager(null)
super.onDestroyView(view)
}
}

//ChildController
class TabViewPageController(args: Bundle) : BaseController() {
private var index: Int = 0
private var contents : IntArray?

init {
index = args.getInt("TabViewPageController.index")
contents = args.getIntArray("TabViewPageController.contents")
}

override val layoutId: Int
get() = R.layout.controller_tab_view_page

override val title: String
get() = ""

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
val v = super.onCreateView(inflater, container)
if (contents != null) {
binding.content.text = Resources.getString(context, contents!![index])
}
return v
}
}

// How i call TabViewController

private fun navigateToPrivacyPolicy() {
val bundle = Bundle()
val headers = intArrayOf(
R.string.header_privacy_policy_1,
R.string.header_privacy_policy_2,
R.string.header_privacy_policy_3
)
val contents = intArrayOf(
R.string.content_privacy_policy_1,
R.string.content_privacy_policy_2,
R.string.content_privacy_policy_3
)
bundle.putString("title", resources.getString(R.string.title_privacy_policy))
bundle.putIntArray("headers", headers)
bundle.putIntArray("contents", contents)
router.pushController(
RouterTransaction.with(TabViewController(bundle))
.popChangeHandler(VerticalChangeHandler())
.pushChangeHandler(VerticalChangeHandler())
)
}

Contributor guide

Open the contributing guide

Research direction

Start with RouterPagerAdapter.configureRouter and trace the Bundle passed to TabViewPageController through RouterTransaction and Controller.newInstance. Compare the bundle created for the child with the bundle read during transaction restoration. Done means the child receives the expected index and contents arguments when created through the pager and router path.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, kotlin
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.