-
Notifications
You must be signed in to change notification settings - Fork 24
Ionic_Profile Screen
Now that we have the Profile Header reusable component ready, it's time to start working on the implementation of My Profile screen.
On My Profile Screen I want to add a picture of the user, his name, occupation, education, interests, what the user is knowledgeable in, and what are his current goals. I want to show the same information both in My Profile Screen and in Contact Screen, with only difference that the Contact Screen is not editable, since it's showing information of other users.
As always, I'm going to start by adding a new folder called profilePage and creating the 3 usual files inside it. This initial process has already been covered on Login Screen page.
We are going to start with the page logic, which will be rather simple (or non-existing) at this point. For now, we'll just obtain a reference to the Profile Header component using ViewChild
, and will add the 5 properties to which our UI components will bind to.
import {Component} from '@angular/core';
import {ProfileHeader} from '../components/profileHeader';
import {ViewChild} from '@angular/core';
@Component({
templateUrl: 'build/pages/profilePage/profilePage.html',
directives: [ProfileHeader],
queries: {
header: new ViewChild('header')
}
})
export class ProfilePage {
constructor() {
this.employment = '';
this.education = '';
this.interests = '';
this.knowledgeable = '';
this.currentGoals = '';
}
ionViewWillEnter(){
this.header.setFullName("Dr. Gregory House");
}
}
Now we are going to design our View. We'll add the code below to the profilePage.html file.
<!-- code omitted for brevity -->
<ion-content padding class="profilePage">
<profile-header #header></profile-header>
<ion-item>
<ion-input type="text" style="margin-top:10px"
placeholder="Head of Diagnostic @ PPT Hospital"
[(ngModel)]="employment"></ion-input>
</ion-item>
<ion-item>
<ion-input type="text"
placeholder="Attended Hopkins University 1979-1984"
[(ngModel)]="education"></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>Interests</ion-label>
<ion-textarea rows="3"
placeholder="Chemistry, Piano , Guitar, Android, Economy, Football..."
[(ngModel)]="interests"></ion-textarea>
</ion-item>
<ion-item>
<ion-label stacked>Knowledgeable In</ion-label>
<ion-textarea rows="3"
placeholder="Classical Music, Fitness, Movie Trivia, HTML5, Android, JavaScript..."
[(ngModel)]="knowledgeable"></ion-textarea>
</ion-item>
<ion-item>
<ion-label stacked>Goals</ion-label>
<ion-textarea rows="3"
placeholder="Learn Ionic2, Find a team for basketball..."
[(ngModel)]="currentGoals"></ion-textarea>
</ion-item>
</ion-content>
ion-input
is meant for text type inputs only, such as text
, password
, email
, number
, search
, tel
, and url
. Ionic still uses an actual <input type="text">
HTML element within the component, however, with Ionic wrapping the native HTML input
element it's able to better handle the user experience and interactivity.
Similarily, <ion-textarea>
should be used in place of <textarea>
placeholder
attribute serves the same purpose as android:hint
on the EditText
view in Android. This is used to specify a text value that will be displayed in an empty input
component, and will disappear after you start typing. This is a pretty useful feature that can help users understand what is expected of them, and what's the purpose of a specific input
.
Labels are placed inside of an ion-item
element and can be used to describe an ion-input
, ion-toggle
, ion-checkbox
, and more.
Label accepts different attributes that makes them behave differently. Here we are using the stacked
attribute. Here's the full list:
- fixed - A persistent label that sits next the input.
- floating - A label that will float about the input if the input is empty or loses focus.
- stacked - A stacked label will always appear on top of the input.
We are using an ion-item
to group together the ion-label
and ion-textarea
, so that our label correctly reacts to user inputs on its corresponding input component.
You probably noticed the [(ngModel)]
attribute on all of our input components. Those attributes are binding to corresponding properties that we defined earlier inside the constructor of our controller. The usage of both the parentheses and brackets [()] tells Angular2 that we want to have a two-way binding on this component.
In total, there are three types of binding:
- [ ] - one-way from the model to the view (aka Property Binding)
- ( ) - one-way from the view to the model (aka Event Bindnig)
- [( )] - two-way where data flows in both directions
I also applied some styling to the inputs and labels.
.profilePage {
ion-label{
font-weight: bold;
font-size: medium;
}
ion-input {
input {
margin-left: 0px;
}
}
}
ion-item{
.text-input {
font-size: large;
}
}
$label-ios-text-color-focused: map-get($colors, secondary);
$label-md-text-color-focused: map-get($colors, secondary);
$label-wp-text-color-focused: map-get($colors, secondary);
$text-input-ios-highlight-color: map-get($colors, secondary);
$text-input-md-highlight-color: map-get($colors, secondary);
$text-input-wp-highlight-color: map-get($colors, secondary);
Ionic2 by default highlights the label and input's border in primary
color. I wanted to change this behavior and use the secondary
color instead, and the above is how I achieved this. The map-get($colors, secondary)
is a sass way of accessing the map $colors
and getting the value for the key secondary
, which basically returns our secondary
color in this case.
Creating the My Profile page wasn't too hard. It was pretty much as straightforward as with Android Native approach, however, I did noticed some limitations. One of them is that the ion-textarea
isn't dynamically adjusting the height as new lines are added to it, which is not the case in Android Native approach. I've read about some third party components that can enable such a feature in Ionic 1, but I haven't yet found anything for Ionic 2.
Below you can see a screenshot of the implemented My Profile page (left), and the Contact page (right) that we'll implement next.
- https://angular.io/docs/js/latest/guide/forms-deprecated.html#!#sts=Two-way%20data%20binding%20with%20*ngModel
- http://ionicframework.com/docs/v2/components/#inputs
- http://ionicframework.com/docs/v2/api/components/input/Input/
- http://ionicframework.com/docs/v2/api/components/input/TextArea/
- http://ionicframework.com/docs/v2/api/components/item/Item/
- http://sass-lang.com/documentation/Sass/Script/Functions.html#map_get-instance_method
- https://github.com/smukov/AvI/commit/66477c0f9a3342f823f70972be56e762b1f7ca52
- https://github.com/smukov/AvI/commit/386f638c57bb7e5fe4adff2d476d11b7b6342c76
- https://github.com/smukov/AvI/commit/022b85ed27885935bf12e4bdd716db77e1de6bd6
- https://github.com/smukov/AvI/commit/39423d6c1dda1a1b5014c1cdb10dc72ebec7d56d
- https://github.com/smukov/AvI/commit/fd4220e1d42dc6aa431f3aefe1f4a446dc484573
- https://github.com/smukov/AvI/commit/c7a5ef6da62b4008e7dee7bd6b7a4d8ab63b144b
- https://github.com/smukov/AvI/commit/5e68521f8a3d7ceda6bcb7904e58643bdf27795d
- https://github.com/smukov/AvI/commit/5014dbd8d8af34312cf59e2334cd31e8f9a42fd0
- Android
- Getting Started
- Project Structure
- Gradle
- Menu
- Theming
- Login Screen
- Menu & Navigation
- Importing Library From GitHub
- Creating Reusable Layouts
- Adding New Icons
- Profile Screen
- Chat Screen
- Contacts Screen
- Pending Invites Screen
- Settings Screen
- Add Library Dependency
- Discover Users Screen
- Splash Screen
- Auth0
- Authentication Logic
- Profile Screen Logic
- Send Feedback
- Authenticated to Firebase via Auth0
- Saving User Info to Firebase
- Storing User Connection Info to Firebase
- Calculating Distance Between Users
- Chat Logic
- Handling Device Rotation
- Android Other
- Ionic
- Getting Started
- Project Structure
- Menu
- Theming
- Login Screen
- Adding Images
- Creating Reusable Layouts
- Adding New Icons
- Profile Screen
- Contact Screen
- Elastic Textarea
- Chat Bubble
- Chat Screen
- Contacts Screen
- Pending Invites Screen
- Settings Screen
- Discover Users Screen
- Splash Screen
- Animations
- Auth0
- Storing User Data
- Profile Screen Logic
- Send Feedback
- Update to Ionic RC0
- Reimplemented Auth0 with Ionic RC0
- Authenticated to Firebase via Auth0
- Saving User Info to Firebase
- Storing User Connection Info to Firebase
- Calculating Distance Between Users
- Chat Logic
- Handling Device Rotation
- Ionic Other
- Version Updating
- Cordova
- Other
- Messaging