Skip to content

Instantly share code, notes, and snippets.

@karaggeorge
Created May 18, 2021 20:01
Show Gist options
  • Save karaggeorge/b61d938822623585e07f21044e6c6623 to your computer and use it in GitHub Desktop.
Save karaggeorge/b61d938822623585e07f21044e6c6623 to your computer and use it in GitHub Desktop.
How to use Global Resources

Using Global Resources

When creating UI we try to re-use as much as we can. This allows for easier refactoring, and good standards in our codebase. Below are some ways to re-use some global resources defined and available in our project.

Colors

In order to use our predefined global colors, you can just add @colors/[color name]. For example: @colors/primaryRed.

If you need a color custom for your feature that is not defined there, you can define it in a local colors.xml in your module.

There should never be hex values directly in a layout file (or any place other than a colors.xml file in general)

If you are following a Figma design file, you can find the color name here:

// FIGMA COLOR IMAGE

Dimensions

When using dimensions, we never use dp values directly in our layouts. We use @dimen/[dimension name].

If you need a generic dimension (multiple of 8), you can just use @dimen/normal_[value] . For example, for 16dp you can use @dimen/normal_16.

If you re-use a specific dimension that has a concept tied to it a lot, you can create a dimens.xml file in your module and define a dimension using a more semantic name (using the above resources as base values).

In the case of global commonly used dimensions, those will be defined in the generic dimens.xml file. For example:

  • @dimens/page_padding -> 16dp

Note: When reading Figma designs, keep the following in mind:

  • Although it assigns widths/heights to all elements, we don't actually set those using dp in our code. We use layouts and constraints, along with paddings/margins, and let the layout form itself.
  • When measuring paddings and margins, keep in mind that all our dimensions are multiples of 8 and that sometimes the Figma inspector is a bit off. So if you see an element with a padding of 15dp on one side and 17dp on the other, it's actually just 16dp horizontal padding.

The above are general guidelines. There is of course always exceptions. Use your best judgement and if you are un-sure, just contact someone in the designer team and ask to verify.

Text Styles - Typography

When using <TextView>s, moving forward with the redesign, we will be using style elements to apply the required styling.

When inspecting a text element in the design you can see the following on the sidebar:

// TEXT STYLE FIGMA IMAGE

That first field is the typography name that is predefined and available to use.

Naming convention examples:

  • App/Body -> TextAppearance.Macys.Body
  • App/Links/Body Small Link -> TextAppearance.Macys.Links.BodySmallLink

To use it, you can just add style="@style/Macys.TextAppearance.Body" to your TextView. If you need a slightly different typography for some reason you can also define one locally in your module extending one of the parent ones.

Note: You shouldn't find a text field that does not have a typography name attached to it. If you do, please contact someone in the design team so they can add it. We shouldn't have custom text in our layouts. They should all be following our typography guidelines and using one of the defined classes. If there's a new appearance and needs to be defined, you can see this document to define it: [Link to other document]

Button Styles

Similar to the text above, we have button styles that we can use to style our <Button> and <MaterialButton> views.

To use them, you can just add style="@style/Macys.Buttons.Primary" (or similar) to your button.

For local, custom buttons, you can create styles in your feature's module.

Images/Drawables

Images and Drawables are usually added to your module's drawables folder. If, however, there's an image or icon that is used very widely in the app, those might exist in the adp-ds-ui module and are accessible to your module by default.

Complex Components

There are some more complex components and abstractions available to use. Some are listed below:

  • Generic RecyclerViewAdapter and Binding
  • Transparent Header
  • Tab Layout controller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment