Base View Binding Dialog Fragment
A base DialogFragment class for DialogFragments that use ViewBinding.
Extends ParentBindingViewDialogFragment to provide common binding functionality.
ViewBinding을 사용하는 DialogFragment를 위한 기본 DialogFragment 클래스입니다.
ParentBindingViewDialogFragment를 상속받아 공통 바인딩 기능을 제공합니다.
Why this class exists / 이 클래스가 필요한 이유:
Android's ViewBinding requires manual inflate() calls for each DialogFragment.
This class eliminates boilerplate by accepting an inflate function reference and automatically setting up the binding.
Provides type-safe view access without findViewById() or synthetic imports.
Android의 ViewBinding은 각 DialogFragment마다 수동으로 inflate() 호출이 필요합니다.
이 클래스는 inflate 함수 참조를 받아 자동으로 바인딩을 설정하여 보일러플레이트를 제거합니다.
findViewById()나 synthetic import 없이 타입 안전한 뷰 접근을 제공합니다.
Design decisions / 설계 결정 이유:
Uses constructor parameter for inflate function reference to enable compile-time type safety.
Implements final createBinding() to prevent subclasses from breaking the binding initialization contract.
Properly handles isAttachToParent parameter for flexible view inflation.
In DialogFragment, keeping the default
falsefor isAttachToParent is recommended unless there is a verified special case.컴파일 타임 타입 안전성을 위해 생성자 파라미터로 inflate 함수 참조를 사용합니다.
final createBinding()을 구현하여 하위 클래스가 바인딩 초기화 계약을 깨는 것을 방지합니다.
유연한 뷰 인플레이션을 위해 isAttachToParent 파라미터를 적절히 처리합니다.
DialogFragment에서는 특별한 경우가 아니라면 isAttachToParent의 기본값
false사용을 권장합니다.
Usage / 사용법:
Extend this class with your DialogFragment and pass the ViewBinding inflate function reference.
Access views through the getBinding() method in onViewCreated() or later lifecycle methods.
Override onViewCreated(binding, savedInstanceState) to perform initial view setup after binding is ready.
DialogFragment에서 이 클래스를 상속받고 ViewBinding inflate 함수 참조를 전달하세요.
onViewCreated() 또는 이후 생명주기 메서드에서 getBinding() 메서드를 통해 뷰에 접근하세요.
바인딩이 준비된 후 초기 뷰 설정을 수행하려면 onViewCreated(binding, savedInstanceState)를 오버라이드하세요.
Usage example:
class HomeDialogFragment : BaseViewBindingDialogFragment<DialogFragmentHomeBinding>(
DialogFragmentHomeBinding::inflate
) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Binding is already initialized and views are ready
getBinding().textView.text = "Hello"
}
}Parameters
The type of ViewBinding class.
ViewBinding 클래스의 타입.
The inflate function reference for the ViewBinding class (e.g., DialogFragmentHomeBinding::inflate).
ViewBinding 클래스의 inflate 함수 참조 (예: DialogFragmentHomeBinding::inflate).
Whether to attach the inflated view to the parent container.
인플레이션된 뷰를 부모 컨테이너에 첨부할지 여부.
DialogFragment에서는 특별한 경우가 아니라면 기본값 false 사용을 권장합니다.
See also
For the parent class providing binding lifecycle.
바인딩 생명주기를 제공하는 부모 클래스는 ParentBindingViewDialogFragment를 참조하세요.
For DataBinding-enabled DialogFragment.
DataBinding을 사용하는 DialogFragment는 BaseDataBindingDialogFragment를 참조하세요.
Properties
Functions
Called immediately after the binding object is created, inside onCreateView().
Use only for binding variable assignment (e.g. binding.vm = vm).
Do NOT access viewLifecycleOwner, start collectors, or call lifecycle-aware APIs here — viewLifecycleOwner is not yet available at this point.
onCreateView() 내부에서 바인딩 객체가 생성된 직후 호출됩니다.
바인딩 변수 할당(예: binding.vm = vm)에만 사용하세요.
viewLifecycleOwner 접근, collector 시작, lifecycle-aware API 호출은 금지입니다 — 이 시점에서는 viewLifecycleOwner를 아직 사용할 수 없습니다.
Cleans up binding and resets helper state.
Always call super.onDestroyView().
바인딩을 정리하고 헬퍼 상태를 초기화합니다.
반드시 super.onDestroyView()를 호출하세요.
Called to start collecting ViewModel events.
Typically invoked once per lifecycle (e.g., onCreate or onViewCreated).
ViewModel 이벤트 수집을 시작할 때 호출됩니다.
보통 생명주기 당 1회(onCreate 또는 onViewCreated) 호출됩니다.
Called when the binding is initialized in onViewCreated().
Implement setup logic that requires binding here.
onViewCreated에서 바인딩이 초기화된 후 호출됩니다.
바인딩이 필요한 초기화 로직을 여기서 수행하세요.
Requests permissions using the delegate.
Call only after the Fragment is attached (isAdded == true).
델리게이트를 사용하여 권한을 요청합니다.
Fragment가 attach된 이후(isAdded == true)에만 호출하세요.
Requests multiple permissions and returns denied results via callback.
여러 권한을 요청하고 거부 결과를 콜백으로 반환합니다.
Safely dismisses the dialog with exception handling.
Catches any exceptions that may occur during dismissal.
예외 처리와 함께 다이얼로그를 안전하게 닫습니다.
닫는 동안 발생할 수 있는 모든 예외를 잡습니다.
Safely shows the dialog with exception handling.
Catches any exceptions that may occur during showing.
예외 처리와 함께 다이얼로그를 안전하게 표시합니다.
표시하는 동안 발생할 수 있는 모든 예외를 잡습니다.
Sets the custom animation style for dialog appearance/disappearance.
Applied immediately if dialog is already showing.
다이얼로그 나타남/사라짐에 대한 커스텀 애니메이션 스타일을 설정합니다.
다이얼로그가 이미 표시 중인 경우 즉시 적용됩니다.
Sets whether the dialog can be canceled by pressing back button or touching outside.
Applied immediately if dialog is already showing.
뒤로 가기 버튼을 누르거나 외부를 터치하여 다이얼로그를 취소할 수 있는지 설정합니다.
다이얼로그가 이미 표시 중인 경우 즉시 적용됩니다.
Sets the position of the dialog on screen.
Applied immediately if dialog is already showing.
화면에서 다이얼로그의 위치를 설정합니다.
다이얼로그가 이미 표시 중인 경우 즉시 적용됩니다.
Creates and shows an indefinite duration Snackbar from a Fragment.
Logs an error if the Fragment's view is null.
Fragment에서 무제한 시간 Snackbar를 생성하고 표시합니다.
Fragment의 view가 null이면 에러를 로깅합니다.
Creates and shows a long duration Snackbar from a Fragment.
Logs an error if the Fragment's view is null.
Fragment에서 긴 시간 Snackbar를 생성하고 표시합니다.
Fragment의 view가 null이면 에러를 로깅합니다.
Creates and shows a short duration Snackbar from a Fragment.
Logs an error if the Fragment's view is null.
Fragment에서 짧은 시간 Snackbar를 생성하고 표시합니다.
Fragment의 view가 null이면 에러를 로깅합니다.
Creates and shows a long duration Toast message from a Fragment.
Logs an error if the Fragment's context is null.
Fragment에서 긴 시간 Toast 메시지를 생성하고 표시합니다.
Fragment의 context가 null이면 에러를 로깅합니다.
Creates and shows a short duration Toast message from a Fragment.
Logs an error if the Fragment's context is null.
Fragment에서 짧은 시간 Toast 메시지를 생성하고 표시합니다.
Fragment의 context가 null이면 에러를 로깅합니다.
Executes the given block and returns a result if the Fragment's context is not null.
Returns null and logs an error if the context is null.
Fragment의 context가 null이 아닌 경우 주어진 블록을 실행하고 결과를 반환합니다.
context가 null이면 null을 반환하고 에러를 로깅합니다.
Executes the given block and returns a result if the Fragment's view is not null.
Returns null and logs an error if the view is null.
Fragment의 view가 null이 아닌 경우 주어진 블록을 실행하고 결과를 반환합니다.
view가 null이면 null을 반환하고 에러를 로깅합니다.