Skip to content

Commit 80fa127

Browse files
committed
fix: properly remove Spans from FormattedString
1 parent 013b898 commit 80fa127

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

Diff for: platform/nativescript/element-registry.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,23 @@ registerElement(
396396
)
397397
registerElement(
398398
'FormattedString',
399-
() => require('@nativescript/core/text/formatted-string').FormattedString
399+
() => require('@nativescript/core/text/formatted-string').FormattedString,
400+
{
401+
insertChild(parentNode, childNode, atIndex) {
402+
if (atIndex) {
403+
parentNode.nativeView.spans.splice(atIndex, 0, childNode.nativeView)
404+
return
405+
}
406+
parentNode.nativeView.spans.push(childNode.nativeView)
407+
},
408+
removeChild(parentNode, childNode) {
409+
const index = parentNode.nativeView.spans.indexOf(childNode.nativeView)
410+
411+
if (index > -1) {
412+
parentNode.nativeView.spans.splice(index, 1)
413+
}
414+
}
415+
}
400416
)
401417
registerElement('Span', () => require('@nativescript/core/text/span').Span)
402418

Diff for: platform/nativescript/renderer/utils.js

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
1-
let View;
1+
let View
22
export function isView(view) {
3-
if (!View) {
3+
if (!View) {
44
View = require('@nativescript/core/ui/core/view').View
55
}
66
return view instanceof View
77
}
88

9-
10-
let LayoutBase;
9+
let LayoutBase
1110
export function isLayout(view) {
12-
if (!LayoutBase) {
11+
if (!LayoutBase) {
1312
LayoutBase = require('@nativescript/core/ui/layouts/layout-base').LayoutBase
1413
}
15-
return (
16-
view instanceof LayoutBase
17-
)
14+
return view instanceof LayoutBase
1815
}
1916

20-
let ContentView;
17+
let ContentView
2118
export function isContentView(view) {
22-
if (!ContentView) {
19+
if (!ContentView) {
2320
ContentView = require('@nativescript/core/ui/content-view').ContentView
2421
}
25-
return (
26-
view instanceof ContentView
27-
)
22+
return view instanceof ContentView
2823
}
2924

3025
export function insertChild(parentNode, childNode, atIndex = -1) {

Diff for: samples/app/app-with-formatted-string.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
const Vue = require('nativescript-vue')
22

3+
Vue.config.silent = false
4+
35
new Vue({
46
template: `
57
<Frame>
68
<Page>
7-
<Label>
9+
<Label @tap="toggle = !toggle">
810
<FormattedString>
911
<Span text="some" fontWeight="Bold" />
1012
<Span text="content" />
13+
<Span v-if="toggle" text="toggled span" color="red" />
1114
</FormattedString>
1215
</Label>
1316
</Page>
1417
</Frame>
1518
`,
1619

17-
comments: true
20+
comments: true,
21+
data() {
22+
return {
23+
toggle: false
24+
}
25+
}
1826
}).$start()

0 commit comments

Comments
 (0)