Skip to content

Commit

Permalink
feat(runtime): navigate frame when inserting child page
Browse files Browse the repository at this point in the history
  • Loading branch information
rigor789 committed Mar 12, 2020
1 parent c6f9a5e commit 2037801
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
3 changes: 0 additions & 3 deletions packages/runtime/src/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,6 @@ function addChild(child: NSVElement, parent: NSVElement, atIndex?: number) {
const childView = child.nativeView

if (parent.meta.viewFlags & NSVViewFlags.NO_CHILDREN) {
// todo: REMOVE this call
// @ts-ignore
parentView.navigate({ create: () => childView })
console.log('NO_CHILDREN')
return
}
Expand Down
41 changes: 35 additions & 6 deletions packages/runtime/src/registry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { ViewBase } from '@nativescript/core'
import {
Frame as TNSFrame,
Page as TNSPage,
ViewBase as TNSViewBase
} from '@nativescript/core'
import { NSVElement, NSVViewFlags } from './nodes'
import { actionBarNodeOps } from './components/ActionBar'
import { warn } from '@vue/runtime-core'

export type NSVElementResolver = () => ViewBase
export type NSVElementResolver = () => TNSViewBase

export interface NSVViewMeta {
viewFlags: NSVViewFlags
Expand Down Expand Up @@ -63,17 +68,17 @@ export function normalizeElementName(elementName: string): string {
export function registerElement(
elementName: string,
resolver?: NSVElementResolver,
meta?: NSVViewMeta
meta?: Partial<NSVViewMeta>
) {
const normalizedName = normalizeElementName(elementName)
meta = Object.assign({}, defaultViewMeta, meta)
const mergedMeta = Object.assign({}, defaultViewMeta, meta)

if (elementMap[normalizedName]) {
throw new Error(`Element for ${elementName} already registered.`)
}

elementMap[normalizedName] = {
meta,
meta: mergedMeta,
resolver
}
console.log(`->registerElement(${elementName})`)
Expand Down Expand Up @@ -152,7 +157,31 @@ export function registerElement(
registerElement(
'Frame',
() => require('@nativescript/core/ui/frame').Frame,
{ viewFlags: NSVViewFlags.NO_CHILDREN }
{
// todo: move into Frame.ts when we end up creating a component for Frame
nodeOps: {
insert(child: NSVElement, parent: NSVElement, atIndex?: number): void {
const frame = parent.nativeView as TNSFrame
if (child.nativeView instanceof TNSPage) {
frame.navigate({
create() {
return child.nativeView
}
})
} else {
if (__DEV__) {
warn(
`<Frame> must only contain <Page> elements - ` +
`got <${child.nativeView.constructor.name}> instead.`
)
}
}
},
remove(child: NSVElement, parent: NSVElement): void {
// ignore? warn? throw? navigate back?
}
}
}
)
registerElement(
'Page',
Expand Down

0 comments on commit 2037801

Please sign in to comment.