If you would like to upgrade to a newer long-term support version of Studio Pro, see Moving from Mendix Studio Pro 8 to 9.
Style Your Mendix Native Mobile App
Introduction
With Mendix 8, you have the capacity to alter design properties with Mendix Studio Pro. Furthermore, because all native mobile styling is written in JavaScript, you have new ways of applying your styling customizations. For more details on native styling, class names, and widget styling, see the Native Mobile Styling Reference Guide.
Prerequisites
- Install an integrated development environment (IDE) of your choice (Mendix recommends Microsoft Visual Studio Code)
- Create a Mendix app based on the Blank Native Mobile App template by following the Creating a New App Based on the Quickstarter App section of Get Started with Native Mobile
- Download the Make It Native 8 app on your mobile device via either the Google Play store or the Apple App Store so you can text your app and see your styling changes
Customizing the Quickstarter App
The Blank Native Mobile App is styled using an Atlas UI resources package. This package consists of:
- Widgets
- Building blocks
- Page templates
- Page layouts
These resources let you style your app with a wide variety of interface parts. However, you can customize them further by following these steps:
-
On your Home_Native home page, delete the Intro screen content.
-
Place a button widget on your app’s home page:
-
Click Run Locally and then click View to see your app. The button will be blue with white text, which is its default styling.
-
Open theme/styles/native/app/custom-variables.js using your IDE of choice.
-
Change the
brand.primary
from #0595DB to rosybrown://Brand Style export const brand = { primary: "rosybrown", success: "#76CA02", warning: "#f99b1d", danger: "#ed1c24", };
-
Save your file.
-
Click Run Locally to apply your changes:
You have successfully altered a default button to look rosy brown These screenshots employ the Make It Native app’s Dark Mode.
Classes
Classes are groups of styling properties which define how certain elements of your app will be rendered. Once you make a class, one which applies to a button for example, you can reuse that class to easily style subsequent buttons in the same way. To learn how to apply a class to a widget, follow the steps below.
-
Place a second button widget on your app’s home page.
-
Run your app to view your button.
-
Select the button widget, and then click the Properties panel. Under Common you will see the button’s Class field.
-
Type btnSuccess into the Class field:
-
Click Run Locally to save and refresh your app. Notice the button turned green:
You have successfully applied an Atlas-provided class to a button widget.
Design Properties
Design properties are easy-to-use classes in Mendix Studio Pro which you do not need to look up before using. Design properties are present inside Mendix Studio Pro with every widget they apply to. They can be accessed in the Properties panel, or by double-clicking the widget and clicking the Appearance tab for more advanced options. Design properties are particularly useful for creating generic styling for use on multiple widgets. Below you will use design properties to alter a button widget.
-
Place a third button widget on your app’s home page.
-
Select the button, and find its Design Properties in the Properties panel.
-
Click the Button style drop-down arrow and select Warning.
-
Run your app again to see the design button’s new color:
Using design properties, you have changed the blue default button widget to orange. For any other warning buttons, you could easily apply the same design property.
Creating Your Own Classes
When you have specific design requirements, you will need to build custom classes to fit. To harness the power of custom classes, follow the instructions below.
-
Place a fourth button widget on your app’s home page.
-
Navigate to your Mendix app’s folder using your IDE.
-
Open the theme folder of your app.
-
Open styles/native/app/custom.js.
-
Copy this code snippet into styles/native/app/custom.js:
export const className = { container: { <ViewStyle properties> }, icon: { }, caption: { <TextStyle properties> } }
To alter a class on your own, consult the Native Mobile Styling Reference Guide to understand widget structures.
-
Now you will edit the code you pasted. Apply a transparent background color to customize the default button widget:
export const className = { container: { backgroundColor: "transparent" }, icon: { }, caption: { } }
-
Because your app already has default styling, you can remove the icon and caption properties. Also, change the constant to a unique, self-explanatory value such as
btnBordered
:export const btnBordered = { container: { backgroundColor: "transparent" }, }
-
Save your work.
-
In Mendix Studio Pro, select your fourth button. In the Properties panel, type btnBordered into the Class field.
-
Click Run Locally to see that your button’s background color is transparent:
You have successfully customized a simple button widget. Using these basic principles, you can go on to customize widgets with distinct looks.
Implementing Custom Design Properties
In this section you will learn to turn the class you made into a design property, so that it can be easily used by other people.
-
Place a fifth button widget on your app’s home page.
-
Open theme/settings-native.json in your IDE.
-
Find the
ActionButton
class. There are already design properties inActionButton
. Next, you will add some of your own. -
Place this object under the first one in
ActionButton
:{ "name": "Bordered", "type": "Toggle", "description": "Create a bordered button.", "class": "btnBordered" },
-
In Mendix Studio Pro, press F4 to synchronize your project directory.
-
Select the fifth button. In Properties > Design Properties, your Bordered design property should now be visible:
-
Enable the Bordered design property by clicking its drop-down menu and selecting Yes.
-
Click Run Locally again and view your app:
You have implemented your own custom design property. Other users can quickly harness your design property without having to consult a class name list.
Congratulations! By completing this how-to, you have learned how to alter a styling property, apply classes and design properties, and create your own classes and design properties.