Thread
#compose
    Mehmet Peker

    Mehmet Peker

    2 years ago
    hello everyone i finally add compose an existing project but i have a question.How can i do activity.onBackpressed on navigation icon click without use navigation library?
    Timo Drick

    Timo Drick

    2 years ago
    So i think the correct way would be to add a callback to your composable. And handle this callback at the point where you do setContent {} in your activty so you have access to the activity.
    Mehmet Peker

    Mehmet Peker

    2 years ago
    Thank you for your solution 😄 I was created fragment instance in companion object and call function but this way seems better
    Timo Drick

    Timo Drick

    2 years ago
    There is also another way to get the activity but maybe not what you should do:
    val activity = ContextAmbient.current as Activity
    So for navigation i would prefere the callback. But there are other use cases where you need an activity to use an system api and do not want to integrate it into your main activity
    Mehmet Peker

    Mehmet Peker

    2 years ago
    Okey i know but how to initialize composable function before setcontent{}
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val binding = FragmentMessageBinding.inflate(LayoutInflater.from(requireContext()), container, false)
        (binding.root as ViewGroup).setContent(Recomposer.current()) {
            MessageScreen(this)
        }
        return binding.root
    }
    
    override fun onNavigationClick() {
        requireActivity().onBackPressed()
    }
    Sorry i must after setContent but how?
    Timo Drick

    Timo Drick

    2 years ago
    You should change your MessageScreen to have a callback ->
    MessageScreen(onNavigaionClick: () -> Unit)
    Than you can write in the setContent part:
    MessageScreen() { onNavigationClick() }
    I don't think it is a good idea to pass the fragment directly to the composables.
    Mehmet Peker

    Mehmet Peker

    2 years ago
    Not working for me.App crashing after click
    Timo Drick

    Timo Drick

    2 years ago
    Can you please post the error back stack
    Mehmet Peker

    Mehmet Peker

    2 years ago
    A part of error 2020-09-10 14:17:43.752 9866-9866/com.zikirmatik.digitaltasbeeh E/InputEventReceiver: Exception dispatching input event. 2020-09-10 14:17:43.753 9866-9866/com.zikirmatik.digitaltasbeeh E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback 2020-09-10 14:17:43.755 9866-9866/com.zikirmatik.digitaltasbeeh E/MessageQueue-JNI: java.lang.IllegalStateException: Internal state has not been set. This method should not be called in any place but after calls to onPointerInputSetup and before calls to onPointerInputTearDown or onCancel. Also, onCustomEvent must be called appropriately. See docs for details.
    Timo Drick

    Timo Drick

    2 years ago
    Sorry too less information to really help you. Maybe you could post the code of the MessageScreen?
    Or just make a simplified version with just one button and try if it is working.
    Mehmet Peker

    Mehmet Peker

    2 years ago
    2020-09-10 14:21:11.400 10009-10126/com.zikirmatik.digitaltasbeeh E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1 2020-09-10 14:21:31.526 10009-10009/com.zikirmatik.digitaltasbeeh E/InputEventReceiver: Exception dispatching input event. 2020-09-10 14:21:31.527 10009-10009/com.zikirmatik.digitaltasbeeh E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback 2020-09-10 14:21:31.531 10009-10009/com.zikirmatik.digitaltasbeeh E/MessageQueue-JNI: java.lang.IllegalStateException: Internal state has not been set. This method should not be called in any place but after calls to onPointerInputSetup and before calls to onPointerInputTearDown or onCancel. Also, onCustomEvent must be called appropriately. See docs for details. at androidx.compose.ui.gesture.scrollorientationlocking.ScrollOrientationLocker.getPointersFor(ScrollOrientationLocker.kt:192) at androidx.compose.ui.gesture.DragSlopExceededGestureFilter.onPointerInput-e3WT7_U(DragSlopExceededGestureFilter.kt:122) at androidx.compose.ui.input.pointer.PointerInputFilter.onPointerEvent-d1fqKvQ(PointerEvent.kt:64) at androidx.compose.ui.input.pointer.Node.dispatchToPointerInputFilter(HitPathTracker.kt:530) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:430) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.NodeParent.dispatchChanges(HitPathTracker.kt:282) at androidx.compose.ui.input.pointer.HitPathTracker.dispatchChanges(HitPathTracker.kt:131) at androidx.compose.ui.input.pointer.PointerInputEventProcessor.process-EhkylT0(PointerInputEventProcessor.kt:71) at androidx.compose.ui.platform.AndroidComposeView.dispatchTouchEvent(AndroidComposeView.kt:578) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:440) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1830) at android.app.Activity.dispatchTouchEvent(Activity.java:3400) at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69) at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:398) at android.view.View.dispatchPointerEvent(View.java:12752) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5106) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4909) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4585) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453) at android.view.ViewRootImpl$AsyncInputStage.apply(Vie 2020-09-10 14:21:31.537 10009-10009/com.zikirmatik.digitaltasbeeh E/AndroidRuntime: FATAL EXCEPTION: main Process: com.zikirmatik.digitaltasbeeh, PID: 10009 java.lang.IllegalStateException: Internal state has not been set. This method should not be called in any place but after calls to onPointerInputSetup and before calls to onPointerInputTearDown or onCancel. Also, onCustomEvent must be called appropriately. See docs for details. at androidx.compose.ui.gesture.scrollorientationlocking.ScrollOrientationLocker.getPointersFor(ScrollOrientationLocker.kt:192) at androidx.compose.ui.gesture.DragSlopExceededGestureFilter.onPointerInput-e3WT7_U(DragSlopExceededGestureFilter.kt:122) at androidx.compose.ui.input.pointer.PointerInputFilter.onPointerEvent-d1fqKvQ(PointerEvent.kt:64) at androidx.compose.ui.input.pointer.Node.dispatchToPointerInputFilter(HitPathTracker.kt:530) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:430) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.Node.dispatchChanges(HitPathTracker.kt:426) at androidx.compose.ui.input.pointer.NodeParent.dispatchChanges(HitPathTracker.kt:282) at androidx.compose.ui.input.pointer.HitPathTracker.dispatchChanges(HitPathTracker.kt:131) at androidx.compose.ui.input.pointer.PointerInputEventProcessor.process-EhkylT0(PointerInputEventProcessor.kt:71) at androidx.compose.ui.platform.AndroidComposeView.dispatchTouchEvent(AndroidComposeView.kt:578) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:440) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1830) at android.app.Activity.dispatchTouchEvent(Activity.java:3400) at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69) at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:398) at android.view.View.dispatchPointerEvent(View.java:12752) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5106) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4909) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4585) 2020-09-10 14:21:31.538 10009-10009/com.zikirmatik.digitaltasbeeh E/AndroidRuntime: at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4642) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7092) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7061) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7022) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7195) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:326) at android.os.Looper.loop(Looper.java:160) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
    Timo Drick

    Timo Drick

    2 years ago
    Sorry did not have this problem yet. Maybe it is a bug of this mixing legacy and compose views?
    I think this is still under heavy development.
    Mehmet Peker

    Mehmet Peker

    2 years ago
    Thank you for everythink i will fork about this
    *work
    Timo Drick

    Timo Drick

    2 years ago
    Can you try:
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
    return ComposeView(requireContext()).apply {
                setContent {
                    MessageView ...
                }
            }
    Mehmet Peker

    Mehmet Peker

    2 years ago
    Not working 😞