Skip to content

Commit

Permalink
Merge pull request #34 from lightning-js/dev
Browse files Browse the repository at this point in the history
Upgraded to Blits 1.4.1. Bumped version to 1.2.0.
  • Loading branch information
michielvandergeest authored Sep 19, 2024
2 parents c9a3e0c + 1265dca commit aebcab3
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 9 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lightningjs/blits-example-app",
"version": "1.1.0",
"version": "1.2.0",
"description": "Lightning 3 Blits Example App",
"main": "index.js",
"type": "module",
Expand Down Expand Up @@ -39,6 +39,6 @@
"vite": "^4.0.4"
},
"dependencies": {
"@lightningjs/blits": "^1.4.0"
"@lightningjs/blits": "^1.4.1"
}
}
Binary file added public/assets/arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ import Slots from './pages/Slots'
import MemoryGame from './pages/MemoryGame'
import Exponential from './pages/Exponential'
import Viewport from './pages/Viewport'
import { RouterHookRoutes } from './pages/RouterHooks.js'
import Resize from './pages/Resize'
import LanguagePlugin from './pages/LanguagePlugin.js'

export default Blits.Application({
template: `
<Element w="1920" h="1080" :color="$backgroundColor">
<RouterView />
<RouterView w="100%" h="100%" />
<!-- <FPScounter x="1610" :show="$showFPS" /> -->
</Element>
`,
Expand Down Expand Up @@ -110,6 +111,9 @@ export default Blits.Application({
{ path: '/examples/events', component: Events },
{ path: '/examples/slots', component: Slots },
{ path: '/examples/viewport', component: Viewport },

...RouterHookRoutes,

{ path: '/examples/resize', component: Resize },
{ path: '/examples/languageplugin', component: LanguagePlugin },
// Benchmarks and stress tests
Expand Down
5 changes: 5 additions & 0 deletions src/pages/Portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ export default Blits.Component('Portal', {
id: 'examples/viewport',
description: 'Lifecycle events when entering and leaving the viewport (margins)',
},
{
title: 'Router Hooks',
id: 'examples/router-hooks',
description: 'Example of router before hook',
},
{
title: 'Image resizing',
id: 'examples/resize',
Expand Down
278 changes: 278 additions & 0 deletions src/pages/RouterHooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
import Blits from '@lightningjs/blits'

const hookPageTemplate = {
template: `
<Element
w="1920"
h="1080"
color="#fff"
:effects="[$shader('radialGradient', {colors: ['#b43fcb', '#6150cb'], pivot: [0.5, 1.1], width: 2400, height: 800})]"
>
<Element :show="$up !== undefined">
<Element src="assets/arrow.png" w="100" h="44" x="960" y="40" mount="{x: 0.5}"/>
<Text :content="$up && $up.toUpperCase()" x="960" y="100" size="76" mount="{x: 0.5}"/>
</Element>
<Element :show="$right !== undefined">
<Element src="assets/arrow.png" w="100" h="44" x="1900" y="540" mount="{x: 1, y: 0.5}" rotation="90"/>
<Text :content="$right && $right.toUpperCase()" x="1760" y="540" size="76" rotation="90" mount="0.5"/>
</Element>
<Element :show="$down !== undefined">
<Element src="assets/arrow.png" w="100" h="44" x="960" y="1040" mount="{x: 0.5, y: 1}" rotation="180"/>
<Text :content="$down && $down.toUpperCase()" x="960" y="980" size="76" mount="{x: 0.5, y: 1}"/>
</Element>
<Element :show="$left !== undefined">
<Element src="assets/arrow.png" w="100" h="44" x="40" y="540" mount="{ y: 0.5}" rotation="-90"/>
<Text :content="$left && $left.toUpperCase()" x="180" y="540" size="76" mount="0.5" rotation="-90"/>
</Element>
<Text :content="$pageTitle" font="raleway" x="960" y="540" size="240" mount="0.5"/>
</Element>
`,
props: [
{
key: 'page',
cast: Object,
},
],
computed: {
pageTitle() {
//compute page title from page data, if there's no page data use default title
return (this.page && this.page.title) || this.title
},
},
state() {
//default state template to indicate which directions will be available if they are defined when "extending"
return {
title: 'Start',
up: 'up',
right: 'right',
down: 'down',
left: 'left',
}
},
}

//landing page of the router hook example, contains 2 flow examples
export const RouterHookPage = Blits.Component('RouterHookPage', {
...hookPageTemplate,
state() {
return {
title: 'Start',
down: 'episode flow',
right: 'movie flow',
}
},
input: {
right() {
//trigger router to navigate to movie flow
this.$router.to('/examples/router-hooks/movie')
},
down() {
//trigger router to navigate to episode flow
this.$router.to('/examples/router-hooks/episode/1')
},
},
})

//movie flow page, with 2 directions left: back, right: rating
const Movie = Blits.Component('RouterHookMovie', {
...hookPageTemplate,
state() {
return {
title: 'Movie',
left: 'Back',
right: 'Rating',
}
},
input: {
left() {
//trigger router back navigation. Leads back to: /examples/router-hooks
this.$router.back()
},
right() {
//trigger router to navigate to rating page
this.$router.to('/examples/router-hooks/rating')
},
},
})

//movie flow page, with 2 directions left: back, right: Router example page landing
const Rating = Blits.Component('RouterHookRating', {
...hookPageTemplate,
state() {
return {
title: 'Rating',
left: 'Back',
right: 'TO START',
}
},
input: {
left() {
//trigger router back navigation. Leads back to: /examples/router-hooks/movie
this.$router.back()
},
right() {
//trigger router to navigate to router hook example page landing
this.$router.to('/examples/router-hooks/')
},
},
})

//movie flow page, with 2 directions left: back, right: next episode
const Episode = Blits.Component('RouterHookEpisode', {
...hookPageTemplate,
state() {
return {
title: 'Episode',
left: 'Back',
right: 'NEXT EPISODE',
}
},
input: {
left() {
//trigger router back navigation. Leads back to: /examples/router-hooks. Even when episode id > 1
this.$router.back()
},
right() {
//trigger router to navigate to the next episode, and NOT save current episode page in navigation history
this.$router.to(`/examples/router-hooks/episode/${this.page.id + 1}`, undefined, {
inHistory: false,
})
},
},
})

//custom page transitions for when the router navigates to router example pages
const PageTransitions = {
slideInOutLeft: {
before: {
prop: 'x',
value: '100%',
},
in: {
prop: 'x',
value: 0,
duration: 400,
},
out: {
prop: 'x',
value: '-100%',
duration: 400,
},
},
slideInOutRight: {
before: {
prop: 'x',
value: '-100%',
},
in: {
prop: 'x',
value: 0,
duration: 400,
},
out: {
prop: 'x',
value: '100%',
duration: 400,
},
},
slideInOutUp: {
before: {
prop: 'y',
value: '100%',
},
in: {
prop: 'y',
value: 0,
duration: 400,
},
out: {
prop: 'y',
value: '-100%',
duration: 400,
},
},
slideInOutDown: {
before: {
prop: 'y',
value: '-100%',
},
in: {
prop: 'y',
value: 0,
duration: 400,
},
out: {
prop: 'y',
value: '100%',
duration: 400,
},
},
}

export const RouterHookRoutes = [
{
path: '/examples/router-hooks',
component: RouterHookPage,
hooks: {
async before(to, from) {
//change transition based on 'from' route
if (from && from.path === 'examples/router-hooks/movie') {
to.transition = PageTransitions.slideInOutRight
}
if (from && from.path === 'examples/router-hooks/rating') {
to.transition = PageTransitions.slideInOutLeft
}
if (from && from.path.indexOf('episode') > -1) {
to.transition = PageTransitions.slideInOutDown
}
return to
},
},
},
{
path: '/examples/router-hooks/episode/:id',
component: Episode,
hooks: {
before(to, from) {
//change transition based on 'from' route
if (from && from.path.indexOf('episode') > -1) {
to.transition = PageTransitions.slideInOutLeft
}
const { id } = to.params
//if id > 5 lead route back to router example page landing
if (id > 5) {
return '/examples/router-hooks/'
}
//set page data based on episode ID
to.data.page = {
id: parseInt(id),
title: `Episode ${id}`,
}
return to
},
},
transition: PageTransitions.slideInOutUp,
},
{
path: '/examples/router-hooks/movie',
component: Movie,
hooks: {
before(to, from) {
//change transition based on 'from' route
if (from && from.path === 'examples/router-hooks') {
to.transition = PageTransitions.slideInOutLeft
}
if (from && from.path === 'examples/router-hooks/rating') {
to.transition = PageTransitions.slideInOutRight
}
return to
},
},
},
{
path: '/examples/router-hooks/rating',
component: Rating,
transition: PageTransitions.slideInOutLeft,
},
]

0 comments on commit aebcab3

Please sign in to comment.