Merge pull request #3 from hariroshan/adding-elements-in-next-animation-frame

Adding elements in next animation frame
This commit is contained in:
Hari Roshan 2023-03-11 16:43:31 +05:30 committed by GitHub
commit 0cc7e25034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 61 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "elm-native-js", "name": "elm-native-js",
"version": "1.0.2", "version": "1.0.3",
"description": "Nativescript bindings for elm using custom HTML elements", "description": "Nativescript bindings for elm using custom HTML elements",
"keywords": ["elm", "elm-native", "nativescript", "elm mobile"], "keywords": ["elm", "elm-native", "nativescript", "elm mobile"],
"main": "index.js", "main": "index.js",

View File

@ -57,6 +57,7 @@ let addView: (. Types.htmlElement, Types.htmlElement) => unit = %raw(`
function(parentElement, thisElement) { function(parentElement, thisElement) {
if (parentElement.data == null) return if (parentElement.data == null) return
requestAnimationFrame(() => {
const children = Array.from(parentElement.children) const children = Array.from(parentElement.children)
const hasActionBar = children.some(x => x.tagName.toLowerCase() === "ns-action-bar") const hasActionBar = children.some(x => x.tagName.toLowerCase() === "ns-action-bar")
const index = children.indexOf(thisElement) const index = children.indexOf(thisElement)
@ -122,6 +123,7 @@ let addView: (. Types.htmlElement, Types.htmlElement) => unit = %raw(`
} }
return (parentElement.data.content = thisElement.data) return (parentElement.data.content = thisElement.data)
})
} }
`) `)
@ -129,9 +131,11 @@ let addFormattedText: (. Types.htmlElement, Types.htmlElement) => unit = %raw(`
function(parentElement, thisElement) { function(parentElement, thisElement) {
if (parentElement.data == null) return if (parentElement.data == null) return
requestAnimationFrame(() => {
const children = Array.from(parentElement.children) const children = Array.from(parentElement.children)
const index = children.indexOf(thisElement) const index = children.indexOf(thisElement)
parentElement.data.formattedText = thisElement.data parentElement.data.formattedText = thisElement.data
})
} }
`) `)
@ -139,9 +143,11 @@ let addSpan: (. Types.htmlElement, Types.htmlElement) => unit = %raw(`
function(parentElement, thisElement) { function(parentElement, thisElement) {
if (parentElement.data == null) return if (parentElement.data == null) return
requestAnimationFrame(() => {
const children = Array.from(parentElement.children) const children = Array.from(parentElement.children)
const index = children.indexOf(thisElement) const index = children.indexOf(thisElement)
parentElement.data.spans.push(thisElement.data) parentElement.data.spans.push(thisElement.data)
})
} }
`) `)