GuidesAPI ReferenceRelease Notes
HomeLog InHome
Guides

BlazeDp - Android

When developing custom UI components in Android, it's crucial to ensure that dimensions are specified in density-independent pixels (DP) rather than raw pixels. This approach maintains consistent sizing across various screen densities and resolutions, providing a more uniform user experience.

In Jetpack Compose, developers frequently use .dp to define sizes and dimensions, ensuring they are density-independent. Similarly, in BlazeSDK, BlazeDp serves this purpose, offering a clear and convenient way for clients to specify dimensions that adapt correctly across different devices.


BlazeDp class and inline value extension:

To facilitate this, the SDK have defined a data class BlazeDp and an extension property blazeDp as follows:

data class BlazeDp(
    private val value: Int
)

inline val Int.blazeDp: BlazeDp get() = BlazeDp(value = this)

Example usage:

// Getting Stories circles preset
val storiesCircles = BlazeWidgetLayout.Presets.StoriesWidget.Row.circles

// Modifying the start margin of the widget's image, using `.blazeDp`
storiesCircles.widgetItemStyle.image.margins.start = 8.blazeDp

// Modifying the end margin of the widget's image, using `BlazeDp()` constructor
storiesCircles.widgetItemStyle.image.margins.start = BlazeDp(8)

Did this page help you?