In this tutorial we are going to build a Hello World HTML5 mobile app that uses Local Storage
Creating new mobile app project
To start we need to create a new mobile project
- To start, we are going to create a new app. From Apps tab, click Start Now button
- Under App Builder, click Go
- Under Mobile App, click Start Now
- Select Blank Mobile App app and click Next Step button
- Enter HTML5LocalStorage for app name and click Create.
- Once the mobile builder has loaded, you should see the following:
We are now ready to build the UI.
Building the UI
- Let's first change the header label. Double click Caption and change the label to HTML5 Local Storage.
- We first need an input field for entering the name. Locate Input component in the Mobile palette and simply drag and drop it into the screen.
- When the input component is dragged into the screen it has a default label of 'Input', delete the label
- With the input component selected, head to Properties tab and rename the component to input (in Common)
- Now locate Button component in the Mobile palette, drag and drop it into the screen and place it below the input component.
- Change the button label to Save. The result should look like this:
- One of the most powerful features in Tiggr is the ability to test the app in desktop or mobile browser. Simply click the Test button to open the app in desktop browser (make sure to allow popups for .gotiggr.com domain. You can also test the app on the mobile device. First make the app public by opening the test Test window and checking Public. You can email the URL to the device or scan the QR code. You may also just type the app link in the mobile browser. We are now ready to create the second screen.
- Select Project > Create New > Screen to create a new mobile screen.
- Keeping the default screen name (mobilescreen2) click OK.
- Change the screen header label to Hello.
- Drag and drop a Label component into the screen, delete its default label.
- Rename the label component to out.
- One last thing, drag and drop a Button component and place it inside the header, on the left-hand side of the label.
- Change the button label to Back. The result should look like this:
We are now ready to add events to store value into Local Storage and then read it from Local Storage for displaying on the second page.
Saving into Local Storage
When the Save button is clicked, we would like to save the value entered in the input field into Local Storage and navigate to the second page.
- Select the Save button and open Events tab.
- From Add Event drop down select Click event
- Once the event is added, from Add Action drop down select Set Local Storage Variable action.
- A window will be shown to create the Local Storage Variable. Enter the following values:
- Variable name: _name
- Bind to Component: check
- Target Component: input
- Property name: text
We are creating a Local Storage variable and binding it to an input component on the screen. In other words, the value entered in the input field will saved into Local Storage under the name of _name.
- Click OK.
- Now we need an action to navigate to the second page. From Add Action drop down select Navigate To Page action
- Select mobilescreen2 from the drop down, click OK. We are done with this page.
- Open mobilescreen2 page (Project > Screens > mobilescreen2)
- We are now going to add an event when the screen loads. Select the screen (you may click outside the phone area to select the screen), then switch to Events tab.
- From Add Event drop down select Load event
- From Add Action drop down select Set Property action to read the value from the Local Storage. Enter the following values:
- Component name: out
- Property name: Text
- Read from local storage variable: check
- Variable: _name
- One last thing we need to do is to define navigation for the Back button. Select the button and add Click event in Events tab.
- From Add Action drop down select Navigate To Page action and select mobilescreen1. Click OK.
- We are ready to test the app. Click the Test button. Enter any value in the input field and click Save. The value entered is saved into Local Storage and then read from the Local Storage when we navigate to the second page.
- Try the app on a mobile device
What's next?
|
|