Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
Please include a sample project that reproduces your issue.
il...@google.com <il...@google.com> #3
Here is the sample project.
Steps to reproduce:
1. Press on "Search" icon;
2. Write something;
3. Search this text, keyboard will be dismissed;
4. Tap on "Dialog" button;
5. Dissmiss dialog;
With the new 1.5.0 fragment library version text will be cleared in the search box after dismissing dialog.
In the version 1.4.1 and lower text in the search is not clearing and this is correct behaviour.
Please suggest some workarounds or how to fix this issue?
Steps to reproduce:
1. Press on "Search" icon;
2. Write something;
3. Search this text, keyboard will be dismissed;
4. Tap on "Dialog" button;
5. Dissmiss dialog;
With the new 1.5.0 fragment library version text will be cleared in the search box after dismissing dialog.
In the version 1.4.1 and lower text in the search is not clearing and this is correct behaviour.
Please suggest some workarounds or how to fix this issue?
Description
androidx.appcompat:appcompat:1.1.0
androidx.fragment:fragment:1.3.0-alpha03
Theme used: Theme.AppCompat.Light.DarkActionBar
Devices/Android versions reproduced on: Pixel 4 (RP1A.200115.001.C1)
Recreating this issue per comment on
Minimal code to reproduce is below. Clicking on the displayed button will cause a crash, as the prior expectation was that in onAttachFragment(), the FragmentManager will contain the Fragment that is passed as a parameter to onAttachFragment(), but this is no longer the case.
_______________
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams
import android.widget.Button
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
private const val FRAGMENT_TAG = "tag"
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
.add(android.R.id.content, StartingFragment(), FRAGMENT_TAG)
.commit()
}
}
override fun onAttachFragment(fragment: Fragment) {
super.onAttachFragment(fragment)
val fragmentByTag = supportFragmentManager.findFragmentByTag(FRAGMENT_TAG)
if (fragment != fragmentByTag) {
throw IllegalStateException("Expected $fragment but found $fragmentByTag")
}
}
fun replaceFragment() {
supportFragmentManager
.beginTransaction()
.replace(android.R.id.content, ReplacementFragment(), FRAGMENT_TAG)
.addToBackStack(null)
.commit()
}
class StartingFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return Button(requireContext()).apply {
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
text = "Replace fragment"
setOnClickListener {
(requireActivity() as MainActivity).replaceFragment()
}
}
}
}
class ReplacementFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return ImageView(requireContext()).apply {
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
setBackgroundColor(Color.BLUE)
}
}
}
}