Fixed
Status Update
Comments
il...@google.com <il...@google.com>
jd...@gmail.com <jd...@gmail.com> #2
We'll track fixing specifically DialogFragment
in this issue.
hu...@google.com <hu...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit 75ee4a9efb5e1f8ff1b1dfca5bfeb151a7605f54
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Feb 22 15:44:08 2021
Set ViewTree owners for dialogs in DialogFragment
While Fragments with a view set their ViewTree owners automatically,
since DialogFragments do not always have a view (as in the case of only
using onCreateDialog), it is possible to have a DialogFragment but no
ViewTree owners set.
We should set the ViewTree owners on the DialogFragment dialog's decor
view. This way it can be accessed.
RelNote: "Dialogs within a DialogFragment can now get access to ViewTree
owners through their DecorView"
Test: testDialogFragmentViewTree
Bug: 180691023
Change-Id: Ib92905306e16dcaee63c985f22b5e36b6718dd39
A fragment/fragment/src/androidTest/java/androidx/fragment/app/DialogFragmentViewTreeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/DialogFragment.java
https://android-review.googlesource.com/1600577
Branch: androidx-main
commit 75ee4a9efb5e1f8ff1b1dfca5bfeb151a7605f54
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Feb 22 15:44:08 2021
Set ViewTree owners for dialogs in DialogFragment
While Fragments with a view set their ViewTree owners automatically,
since DialogFragments do not always have a view (as in the case of only
using onCreateDialog), it is possible to have a DialogFragment but no
ViewTree owners set.
We should set the ViewTree owners on the DialogFragment dialog's decor
view. This way it can be accessed.
RelNote: "Dialogs within a DialogFragment can now get access to ViewTree
owners through their DecorView"
Test: testDialogFragmentViewTree
Bug: 180691023
Change-Id: Ib92905306e16dcaee63c985f22b5e36b6718dd39
A fragment/fragment/src/androidTest/java/androidx/fragment/app/DialogFragmentViewTreeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/DialogFragment.java
hu...@google.com <hu...@google.com> #4
This has been fixed internally and will be released as part of the Fragment 1.3.1
version.
You can verify this by following the 7166224
and switching your fragment dependency to 1.4.0-SNAPSHOT
.
ap...@google.com <ap...@google.com> #5
With this bug essentially meaning that DialogFragments cannot be used with Compose, would it be possible to please backport this fix into the Fragment 1.3.0
version?
jd...@gmail.com <jd...@gmail.com> #7
Hi again,
The generated error is: "androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.canonicalexamples.realprogrammers:id/menu_item_save".
Running the application displays that button. However, the (partial) hierarchy shown in the log is:
"+---->ActionMenuView{id=-1, visibility=VISIBLE, width=56, height=48, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.view.ViewGroup$LayoutParams@340d8ce3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=264.0, y=0.0, child-count=1}
|
+----->OverflowMenuButton{id=-1, desc=More options, visibility=VISIBLE, width=56, height=48, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.ActionMenuView$LayoutParams@1c10a9c8, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+--->ActionBarContextView{id=16908677, res-name=action_context_bar, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@c883991, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
+-->ActionBarContainer{id=16909335, res-name=split_action_bar, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=com.android.internal.widget.ActionBarOverlayLayout$LayoutParams@820620, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0} "
Best regards,
Jorge
The generated error is: "androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.canonicalexamples.realprogrammers:id/menu_item_save".
Running the application displays that button. However, the (partial) hierarchy shown in the log is:
"+---->ActionMenuView{id=-1, visibility=VISIBLE, width=56, height=48, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.view.ViewGroup$LayoutParams@340d8ce3, tag=null, root-is-layout-requested=false, has-input-connection=false, x=264.0, y=0.0, child-count=1}
|
+----->OverflowMenuButton{id=-1, desc=More options, visibility=VISIBLE, width=56, height=48, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.ActionMenuView$LayoutParams@1c10a9c8, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+--->ActionBarContextView{id=16908677, res-name=action_context_bar, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@c883991, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
+-->ActionBarContainer{id=16909335, res-name=split_action_bar, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=com.android.internal.widget.ActionBarOverlayLayout$LayoutParams@820620, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0} "
Best regards,
Jorge
Description
Version used: 1.1.0-alpha02
Devices/Android versions reproduced on: emulator
I am trying to test that a menu option is enabled or disabled when needed using Robolectric 4.0.2. The test will be something like:
@Test
fun enableSaveButton() {
sut.onFragment {
// TODO: trigger onCreateOptionsMenu(menu: Menu, inflater: MenuInflater)
openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext())
it.enableSaveButton(false)
}
onView(withId(R.id.menu_item_save)).check(matches(not(isEnabled())))
}
The fragment is launched and reaches the resumed state, but in the lamda that "onFragment" executes, onCreateMenuOptions() has NOT been executed yet becaues that is how the fragment lifecycle works (
I have also tried using Espresso's "openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext())" unsuccessfully.