Skip to content

Some tips

Davide Giuseppe Farella edited this page Mar 13, 2019 · 1 revision

The lib is built on 3 focal points:

  • Customization
  • Easiness
  • Compactness

The first two are pretty self-explanatory, while the third one means that you should be able to write your fully customized Drawer with the less lines of code as possible; in other word is suggested to use an approach like this:

with DSL:

drawer {
    header { ... }
    body {
        val myBadge = Badge {
            backgroundCornerRadiusDp = 999f // Round badge
            backgroundColorRes = R.color.color_badge_background
            contentColorRes = R.color.color_badge_content
        }
        allPrimary { 
            badgeItem = myBadge 
            titleSizeSp = 20f
            titleColor = Color.RED
        }
        primaryItem( "First" ) { badgeContentText = "1" " }
        primaryItem( "Second" ) { /* No badge content, so the badge will be hidden */ }
    }
}

withou DSL:

val myBadge = BadgeItem()
    .backgroundCornerRadiusDp( 999f ) // Round badge
    .backgroundColorRes( R.color.color_badge_background )
    .contentColorRes( R.color.color_badge_content )

class MyPrimaryDrawerItem() { init {
    badge( myBadge )
    titleSizeSp( 20f )
    titleColor( Color.RED )
} }

val firstItem = MyPrimaryDrawerItem()
    .titleText( "First")
    .badgeContentText( "1" )

val secondItem = MyPrimaryDraweItem()
    .titleText( "Second" )
    // No badge content, so the badge will be hidden.
Clone this wiki locally