Плавная прокрутка в EditText

Я пытаюсь воспроизвести аналогичный эффект в моем приложении. Ниже приведен код, который я использую для этого:
TodoInputDialogFragment.kt
Код: Выделить всё
class TodoInputDialogFragment : BottomSheetDialogFragment() {
private var _binding: TodoInputDialogFragmentBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
private var keyboardVisible = false
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = TodoInputDialogFragmentBinding.inflate(inflater, container, false)
val root: View = binding.root
// https://stackoverflow.com/questions/64947700/how-to-adjust-dialog-layout-when-soft-keyboard-appears-using-the-latest-windowin
ViewCompat.setOnApplyWindowInsetsListener(root) { _, insets ->
// https://stackoverflow.com/a/63595830/72437
val currKeyboardVisible = insets.isVisible(WindowInsetsCompat.Type.ime())
if (!currKeyboardVisible && (this.keyboardVisible != currKeyboardVisible)) {
dismiss()
}
this.keyboardVisible = currKeyboardVisible
insets
}
binding.submitButton.setOnClickListener {
submit()
}
return root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
focusAndShowKeyboard(requireActivity(), binding.editText)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
// https://stackoverflow.com/questions/64947700/how-to-adjust-dialog-layout-when-soft-keyboard-appears-using-the-latest-windowin
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
dialog.window?.also {
it.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
}
}
// https://stackoverflow.com/questions/46861306/how-to-disable-bottomsheetdialogfragment-dragging
dialog.setOnShowListener { dialogInterface ->
val bottomSheet = dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet)
if (bottomSheet != null) {
val behavior: BottomSheetBehavior = BottomSheetBehavior.from(bottomSheet)
behavior.isDraggable = false
}
}
return dialog
}
override fun getTheme(): Int {
return com.xxx.R.style.TodoInputDialogFragmentStyle
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
private fun submit() {
}
}
Код: Выделить всё
@style/BottomSheet_Rounded
adjustResize
false
Код: Выделить всё
Лаговая прокрутка в EditText (
Код: Выделить всё
BottomSheetDialogFragment

Я пробую другую реализацию, используя DialogFragment в сочетании с EditText.
CustomDialogFragment. КТ
Код: Выделить всё
class CustomDialogFragment : DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.dialog_custom, container, false)
}
override fun onStart() {
super.onStart()
dialog?.window?.apply {
// Set the layout parameters of the dialog window
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
// Adjust the window to be resized when the keyboard appears
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
}
}
}
Код: Выделить всё
Код: Выделить всё
DialogFragment

Знаете, почему это так? Почему некоторые приложения могут обеспечить плавную прокрутку в EditText, когда они используют его с BottomSheetDialogFragment или DialogFragment?
Подробнее здесь: https://stackoverflow.com/questions/783 ... t-dialogfr