Skip to content

nice11-lab/ViewBindingPropertyDelegate

 
 

Repository files navigation

ViewBindingPropertyDelegate

Make work with Android View Binding simpler

Add library to a project

allprojects {
  repositories {
    jcenter()
  }
}

dependencies {
    implementation 'com.kirich1409.viewbindingpropertydelegate:viewbindingpropertydelegate:1.0.0-beta1'
}

Samples

class ProfileFragment : Fragment(R.layout.profile) {

    private val viewBinding: ProfileBinding by viewBinding()
}
class ProfileActivity : AppCompatActivity(R.layout.profile) {

    private val viewBinding: ProfileBinding by viewBinding(R.id.container)
}
class ProfileDialogFragment : DialogFragment() {

    private val viewBinding: ProfileBinding by dialogViewBinding(R.id.container)

    // Creating via default way will work too for that case
    // private val viewBinding: ProfileBinding by viewBinding()

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        return AlertDialog.Builder(requireContext())
            .setView(R.layout.profile)
            .create()
    }
}
class ProfileDialogFragment : DialogFragment() {

    private val viewBinding: ProfileBinding by dialogViewBinding(R.id.container)

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.profile, container, false)
    }
}

Packages

No packages published

Languages

  • Kotlin 100.0%