Skip to content

Commit

Permalink
fix: properly remove Spans from FormattedString
Browse files Browse the repository at this point in the history
  • Loading branch information
rigor789 committed May 20, 2020
1 parent 013b898 commit 80fa127
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
18 changes: 17 additions & 1 deletion platform/nativescript/element-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,23 @@ registerElement(
)
registerElement(
'FormattedString',
() => require('@nativescript/core/text/formatted-string').FormattedString
() => require('@nativescript/core/text/formatted-string').FormattedString,
{
insertChild(parentNode, childNode, atIndex) {
if (atIndex) {
parentNode.nativeView.spans.splice(atIndex, 0, childNode.nativeView)
return
}
parentNode.nativeView.spans.push(childNode.nativeView)
},
removeChild(parentNode, childNode) {
const index = parentNode.nativeView.spans.indexOf(childNode.nativeView)

if (index > -1) {
parentNode.nativeView.spans.splice(index, 1)
}
}
}
)
registerElement('Span', () => require('@nativescript/core/text/span').Span)

Expand Down
21 changes: 8 additions & 13 deletions platform/nativescript/renderer/utils.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
let View;
let View
export function isView(view) {
if (!View) {
if (!View) {
View = require('@nativescript/core/ui/core/view').View
}
return view instanceof View
}


let LayoutBase;
let LayoutBase
export function isLayout(view) {
if (!LayoutBase) {
if (!LayoutBase) {
LayoutBase = require('@nativescript/core/ui/layouts/layout-base').LayoutBase
}
return (
view instanceof LayoutBase
)
return view instanceof LayoutBase
}

let ContentView;
let ContentView
export function isContentView(view) {
if (!ContentView) {
if (!ContentView) {
ContentView = require('@nativescript/core/ui/content-view').ContentView
}
return (
view instanceof ContentView
)
return view instanceof ContentView
}

export function insertChild(parentNode, childNode, atIndex = -1) {
Expand Down
12 changes: 10 additions & 2 deletions samples/app/app-with-formatted-string.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
const Vue = require('nativescript-vue')

Vue.config.silent = false

new Vue({
template: `
<Frame>
<Page>
<Label>
<Label @tap="toggle = !toggle">
<FormattedString>
<Span text="some" fontWeight="Bold" />
<Span text="content" />
<Span v-if="toggle" text="toggled span" color="red" />
</FormattedString>
</Label>
</Page>
</Frame>
`,

comments: true
comments: true,
data() {
return {
toggle: false
}
}
}).$start()

0 comments on commit 80fa127

Please sign in to comment.