Git Product home page Git Product logo

inline-view-binding's Introduction

inline-view-binding

Library to simplify ViewBinding usage and save your life

ic_inline

Setup

Add this to build.gradle (project)

allprojects {
  repositories {
      ...
      maven { url 'https://jitpack.io' }
    }
}

Add this dependency to build.grdle (module) or if you using gradle 7+ put it to setting.gradle

android {
    // you also need add view binding library as usual
    buildFeatures {
        viewBinding true
    }
}

dependencies {
  implementation 'com.github.derysudrajat:inline-view-binding:1.0.1'
}

How to use

Here how to easy use binding on Activity and Fragment, enjoy ๐Ÿ˜Žโœจ

In Activity

You can use the delegate property by viewBinding(YourLayoutBinding::inflate) to use this library and voila just it you can use view binding as usual

class MainActivity : AppCompatActivity() {

    // just using delegate by view binding to and inflate your layout like this
    private val binding by viewBinding(ActivityMainBinding::inflate)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        // ... do your magic here
    } 
}

In Fragment

In Fragment you need to Extend your fragment class with BindingFragment<YourLayoutBinding> and you will override binding variable After that you just need to use same delegete property like in Activity by viewBinding(YourLayoutBinding::inflate), and All done ๐Ÿฅณ

// extend your fragment class to BindingFragment with your generic layout
class SampleFragment : BindingFragment<FragmentSampleBinding>() {

    // just using delegate by view binding and inflate your layout like this
    override val binding by viewBinding(FragmentSampleBinding::inflate)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // ... do your magic here
    }

}

That's it enjoy the library ๐Ÿฅณ, give me star if you like this library, ciaaoo ๐Ÿ˜Žโœจ

inline-view-binding's People

Contributors

derysudrajat avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.