Skip to content

Commit

Permalink
Update Experience Section to handle mobile gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermeborgesbastos committed Mar 13, 2021
1 parent cfb905d commit cd54bb4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
22 changes: 19 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ import { AngularFireDatabaseModule } from "@angular/fire/database";
import { AngularFireAnalyticsModule } from "@angular/fire/analytics";
import { environment } from "../environments/environment";

import { HammerModule, HammerGestureConfig, HAMMER_GESTURE_CONFIG } from "@angular/platform-browser";
import * as Hammer from "hammerjs";

export class MyHammerConfig extends HammerGestureConfig {
overrides = <any> {
swipe: { direction: Hammer.DIRECTION_ALL },
};
}

registerLocaleData(localeEn, "en");
registerLocaleData(localePt, "pt-BR", localePtExtra);
@NgModule({
imports: [
imports: [
BrowserModule,
AppRoutingModule,
CoreModule,
Expand All @@ -30,10 +39,17 @@ registerLocaleData(localePt, "pt-BR", localePtExtra);
PageNotFoundRoutingModule,
AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFireDatabaseModule,
AngularFireAnalyticsModule
AngularFireAnalyticsModule,
HammerModule
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
bootstrap: [ AppComponent ],
providers: [
{
provide: HAMMER_GESTURE_CONFIG,
useClass: MyHammerConfig,
},
]
})

export class AppModule {}
10 changes: 5 additions & 5 deletions src/app/experience/experience.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
<h1 i18n="nav@@experiences">Experiences</h1>
</div>
<div class="navigation">
<a href="javascript:void(0)" class="previous" (click)="onClickPrevious()" [ngClass]="{'disabled': currentPosition == 1}">
<a href="javascript:void(0)" class="previous" (click)="onClickPrevious()" [ngClass]="{'disabled': disablePreviousNavigation()}">
<fa-icon [icon]="['fas', 'chevron-left']" class="icon" i18n-title="exp.nav@@previous" title="Previous"></fa-icon>
<span i18n="exp.nav@@previous">Previous</span>
</a>
<div class="devider">|</div>
<a href="javascript:void(0)" class="next" (click)="onClickNext()" [ngClass]="{'disabled': currentPosition == experiencesOrdered?.length}">
<a href="javascript:void(0)" class="next" (click)="onClickNext()" [ngClass]="{'disabled': disableNextNavigation()}">
<span i18n="exp.nav@@next">Next</span>
<fa-icon [icon]="['fas', 'chevron-right']" class="icon" i18n-title="exp.nav@@next" title="Next"></fa-icon>
</a>
</div>

<!-- Custom mobile menu active under 600px wide resolution -->
<div class="navigation-mobile">
<a href="javascript:void(0)" class="previous" (click)="onClickPrevious()" [ngClass]="{'disabled': currentPosition == 1}">
<a href="javascript:void(0)" class="previous" (click)="onClickPrevious()" [ngClass]="{'disabled': disablePreviousNavigation()}">
<div class="molding">
<span [innerHtml]="previousYear | safariDateFormatter | localizedDate:'yyyy'"></span>
<fa-icon [icon]="['fas', 'chevron-left']" class="icon" i18n-title="exp.nav@@previous" title="Previous"></fa-icon>
</div>
</a>
<div class="current"><span [innerHtml]="currentYear | safariDateFormatter | localizedDate:'yyyy'"></span></div>
<a href="javascript:void(0)" class="next" (click)="onClickNext()" [ngClass]="{'disabled': currentPosition == experiencesOrdered?.length}">
<a href="javascript:void(0)" class="next" (click)="onClickNext()" [ngClass]="{'disabled': disableNextNavigation()}">
<div class="molding">
<fa-icon [icon]="['fas', 'chevron-right']" class="icon" i18n-title="exp.nav@@next" title="Next"></fa-icon>
<span [innerHtml]="nextYear | safariDateFormatter | localizedDate:'yyyy'"></span>
Expand All @@ -35,7 +35,7 @@ <h1 i18n="nav@@experiences">Experiences</h1>
</div>
</div>

<div class="middle-container">
<div class="middle-container" (swipe)="onSwipe($event)">
<div class="events-content">
<ol #orderedList>
<li *ngFor="let exp of experiencesOrdered; let i = index" [ngClass]="{'selected': i == 0}" data-id="{{ exp.id }}">
Expand Down
22 changes: 22 additions & 0 deletions src/app/experience/experience.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { DataService } from "../core/data.service";
import { SorterService } from "../core/sorter.service";
import { FaIconLibrary } from "@fortawesome/angular-fontawesome";

enum Direction {
Left,
Right,
}

@Component({
selector: "app-experience",
templateUrl: "./experience.component.html",
Expand Down Expand Up @@ -56,6 +61,23 @@ export class ExperienceComponent implements OnInit {
});
}

public onSwipe(event) {
const direction: Direction = Math.abs(event.deltaX) > 40 ? (event.deltaX > 0 ? Direction.Right : Direction.Left) : undefined;
if(!this.disablePreviousNavigation() && direction === Direction.Right) {
this.onClickPrevious();
} else if(!this.disableNextNavigation() && direction === Direction.Left) {
this.onClickNext();
}
}

public disablePreviousNavigation(): boolean {
return this.currentPosition === 1;
}

public disableNextNavigation(): boolean {
return this.currentPosition === this.experiencesOrdered?.length;
}

// Preloads the boundaries images related to the current position in order to avoid the "blinking" of the background while navigating.
private preloadBounderyImages(images: string[]) {
images.forEach(function (image, i) {
Expand Down
2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ if (environment.production) {
enableProdMode();
}



platformBrowserDynamic().bootstrapModule(AppModule)
.catch((err) => console.error(err));

0 comments on commit cd54bb4

Please sign in to comment.