Shivam Kanodia
09/18/2023, 12:42 PMclass RecceSectionsComponent(
componentContext: ComponentContext,
recceId: String,
sectionId: String,
sectionTitle: String,
recceGuide: Guide?,
projectId: String?,
storeFactory: StoreFactory,
private val output: (Output) -> Unit
) : ComponentContext by componentContext {
private val recceStore = instanceKeeper.getStore {
RecceDetailsStoreFactory(
storeFactory = storeFactory
).create()
}
private val backCallback = BackCallback {
onOutput(Output.NavigateBack)
}
init {
lifecycle.subscribe(object : Lifecycle.Callbacks {
override fun onResume() {
super.onResume()
}
override fun onStart() {
super.onStart()
}
})
backHandler.register(backCallback)
backCallback.isEnabled = true
}
val recceId = recceId
val sectionId = sectionId
val sectionTitle = sectionTitle
val recceGuide = recceGuide
val projectId = projectId
@OptIn(ExperimentalCoroutinesApi::class)
val state: StateFlow<RecceDetailsStore.State> = recceStore.stateFlow
fun onEvent(event: RecceDetailsStore.Intent) {
recceStore.accept(event)
}
fun onOutput(output: Output) {
output(output)
}
sealed class Output {
object NavigateBack : Output()
object Logout : Output()
data class OpenFullScreenComponent<T>(
val imagesList: List<T>,
val initialImageIndex: Int,
val openFrom: String,
val elementName: String? = null
) : Output()
}
}
Above is RecceSectionsComponent declared in RootComponent.
private val navigation = StackNavigation<Configuration>()
private val stack = childStack(
source = navigation,
initialConfiguration = getInitConfig(),
childFactory = ::createChild
)
This is stack in RootCOmponent. I want to pop this component on backpressed, How to Dispacht and inboke this backHandler?Arkadii Ivanov
09/18/2023, 12:57 PMShivam Kanodia
09/18/2023, 1:06 PMprivate val navigation = StackNavigation<Configuration>()
private val stack = childStack(
source = navigation,
initialConfiguration = getInitConfig(),
childFactory = ::createChild,
handleBackButton = true
)
it says to do something like this, right? But its not workingArkadii Ivanov
09/18/2023, 1:08 PMBackCallback
in your child component.Shivam Kanodia
09/18/2023, 1:08 PMShivam Kanodia
09/18/2023, 1:10 PMsealed class Child {
data class EnterMobileNumber(val component: EnterMobileNumberComponent) : Child()
data class EnterOtp(val component: EnterOtpComponent) : Child()
data class ProjectListing(val component: ProjectListingComponent) : Child()
data class ProjectDetails(val component: ProjectDetailsComponent) : Child()
data class ImagePreviewFullScreen(val component: ImagePreviewFullScreenComponent) : Child()
data class Notifications(val component: NotificationsComponent) : Child()
data class ElementDetails(val component: ElementDetailsComponent) : Child()
data class OutgoingOrders(val component: OutgoingOrderComponent) : Child()
data class WorkProgressPreviewFullScreen(val component: WorkProgressPreviewComponent) :
Child()
data class DesignPreviewScreen(val component: DesignPreviewComponent) : Child()
data class EmptyNotificationScreen(val component: EmptyNotificationComponent) : Child()
data class GenerateReport(val component: GenerateReportComponent) : Child()
data class Recces(val component: RecceComponent) : Child()
data class ReccesDetails(val component: RecceDetailsComponent) : Child()
data class RecceSections(val component: RecceSectionsComponent) : Child()
}
There are children of stack in RootComponentShivam Kanodia
09/18/2023, 1:11 PMval childStack: Value<ChildStack<*, Child>> = stack
private fun createChild(
configuration: Configuration, componentContext: ComponentContext
): Child = when (configuration) {
is Configuration.EnterMobileNumber -> Child.EnterMobileNumber(
enterMobileNumber(
componentContext, ::onEnterMobileNumberOutput
)
)
is Configuration.EnterOtp -> Child.EnterOtp(
enterOtp(
componentContext,
configuration.mobile,
configuration.verificationId,
::onEnterOtpOutput
)
)
is Configuration.ProjectListing -> Child.ProjectListing(
projectListing(componentContext, ::onProjectListingOutput)
)
is Configuration.ProjectDetails -> Child.ProjectDetails(
projectDetails(
componentContext, configuration.projectId, ::onProjectDetailsOutput
)
)
is Configuration.RecceDetails -> Child.ReccesDetails(
recceDetails(
componentContext, configuration.recceId, ::onRecceDetailsOutput
)
)
is Configuration.ImagePreviewFullScreen -> Child.ImagePreviewFullScreen(
imagePreviewFullScreen(
componentContext,
configuration.imagesList,
configuration.initialImageIndex,
configuration.openFrom,
configuration.elementName.toString(),
::onImagePreviewOutput
)
)
is Configuration.Notification -> Child.Notifications(
notifications(
componentContext, ::onNotificationsOutput
)
)
is Configuration.GenerateReport -> Child.GenerateReport(
generateReport(componentContext, configuration.projectId, ::onGenerateReportOutput)
)
is Configuration.ElementDetails -> Child.ElementDetails(
elementDetails(
componentContext,
configuration.projectId,
configuration.elementId,
configuration.position,
configuration.projectUpdateRes,
configuration.projectDetailsPermissionsResponse,
configuration.myScopeElementRes,
::onElementDetailsOutput
)
)
is Configuration.OutgoingOrders -> Child.OutgoingOrders(
outgoingOrders(
componentContext,
configuration.projectId,
configuration.vendorOrderId,
configuration.orderType,
::onOutgoingOrdersOutput
)
)
is Configuration.WorkProgressPreviewScreen -> Child.WorkProgressPreviewFullScreen(
workProgressPreviewFullScreen(
componentContext,
configuration.context,
configuration.progress_report_id,
configuration.projectId,
::onWorkProgressPreviewFullScreenOutput
)
)
is Configuration.DesignPreviewScreen -> Child.DesignPreviewScreen(
designPreviewScreen(
componentContext,
configuration.projectId,
configuration.fileId,
configuration.downloadedPath,
::onDesignPreviewScreenOutput
)
)
is Configuration.EmptyNotificationScreen -> Child.EmptyNotificationScreen(
emptyNotificationScreen(
componentContext, configuration.context, ::onEmptyNotificationScreenOutput
)
)
is Configuration.Recce -> Child.Recces(
recces(
componentContext, ::onRecceOutput
)
)
is Configuration.RecceSection -> Child.RecceSections(
recceSections(
componentContext,
configuration.recceId,
configuration.sectionId,
configuration.sectionTitle,
configuration.recceGuide,
configuration.projectId,
::onRecceEditOutput
)
)
}
Arkadii Ivanov
09/18/2023, 1:11 PMShivam Kanodia
09/18/2023, 1:11 PMShivam Kanodia
09/18/2023, 1:15 PMArkadii Ivanov
09/18/2023, 1:16 PMShivam Kanodia
09/18/2023, 1:17 PMShivam Kanodia
09/18/2023, 1:22 PM@Arkadii Ivanov
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
requireContext().applicationContext.let { AppContext.setContext(it) }
pref.put(RdashConstants.AUTH_TOKEN, authToken)
AppContext.setFrag(this)
connectivityReceiver = ConnectivityReceiver()
requireActivity().registerReceiver(
connectivityReceiver,
IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
)
val rootComponent = RootComponent(
componentContext = defaultComponentContext(onBackPressedDispatcher = requireActivity().onBackPressedDispatcher),
storeFactory = DefaultStoreFactory(),
initComponent = RbConstants.RECCE_COMPONENT,
recceDetailClickCallback = recceDetailClickCallback,
)
return ComposeView(requireContext()).apply {
setContent {
RbSharedTheme {
Surface(
color = RbSharedColors.background, modifier = Modifier.fillMaxSize()
) {
RootContent(rootComponent)
}
}
}
}
}
Still not working, sameShivam Kanodia
09/18/2023, 1:22 PMprivate val navigation = StackNavigation<Configuration>()
private val stack = childStack(
source = navigation,
initialConfiguration = getInitConfig(),
childFactory = ::createChild,
handleBackButton = true
)
Arkadii Ivanov
09/18/2023, 1:24 PMonCreate
instead. It should work.Arkadii Ivanov
09/18/2023, 1:26 PMShivam Kanodia
09/18/2023, 1:26 PMShivam Kanodia
09/18/2023, 1:27 PMArkadii Ivanov
09/18/2023, 1:27 PMShivam Kanodia
09/18/2023, 1:28 PMShivam Kanodia
09/18/2023, 1:28 PMArkadii Ivanov
09/18/2023, 1:28 PMThen how should i override onBackPressed of activity or fragment?You shouldn't, I believe it's deprecated. You can register your own back callbacks.
Shivam Kanodia
09/18/2023, 1:29 PMShivam Kanodia
09/18/2023, 1:29 PMArkadii Ivanov
09/18/2023, 1:30 PMShivam Kanodia
09/18/2023, 1:30 PMArkadii Ivanov
09/18/2023, 1:32 PMhow should i handle or register my callbacks then?Why do you need it? I thought you need to pop a child from the Decompose stack by pressing the back button. It works automatically if you supply
handleBackButton = true
argument. However, somewhere else (e.g. in the Activity or another Fragment), you may have a back callback registered and enabled, which may prevent Decompose from handling the back button.
Back callbacks are checked in reverse order.Shivam Kanodia
09/18/2023, 1:33 PMArkadii Ivanov
09/18/2023, 1:33 PMShivam Kanodia
09/18/2023, 1:33 PMShivam Kanodia
09/18/2023, 1:36 PMShivam Kanodia
09/18/2023, 1:36 PMShivam Kanodia
09/18/2023, 1:37 PMArkadii Ivanov
09/18/2023, 1:43 PMhandleBackButton = true
argument in that childStack
. Please double check the following:
1. Make sure that the stack has more than just one component.
2. Check if something prevents Decompose from handling the back button. E.g. try debugging OnBackPressedDispatcher
of the hosting Activity, and see if the are any other callbacks in there, preventing Decompose from handling.
I you believe it's a bug in Decompose, please file an issue with a reproducer here: https://github.com/arkivanov/Decompose/issuesShivam Kanodia
09/18/2023, 1:44 PMShivam Kanodia
09/18/2023, 1:50 PMArkadii Ivanov
09/18/2023, 1:53 PMShivam Kanodia
09/18/2023, 1:54 PMShivam Kanodia
09/25/2023, 7:17 AM