mirror of https://github.com/anoshenko/rui.git
Optimisation
This commit is contained in:
parent
6b2a5b4aee
commit
488368de8c
|
@ -223,6 +223,13 @@ function appendToInputValue(elementId, content) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeView(elementId) {
|
||||||
|
const element = document.getElementById(elementId);
|
||||||
|
if (element) {
|
||||||
|
element.remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setDisabled(elementId, disabled) {
|
function setDisabled(elementId, disabled) {
|
||||||
const element = document.getElementById(elementId);
|
const element = document.getElementById(elementId);
|
||||||
if (element) {
|
if (element) {
|
||||||
|
|
111
stackLayout.go
111
stackLayout.go
|
@ -176,7 +176,7 @@ func (layout *stackLayoutData) transitionFinished(view View, tag PropertyName) {
|
||||||
|
|
||||||
case "pop":
|
case "pop":
|
||||||
if finished, ok := layout.onPopFinished[viewID]; ok {
|
if finished, ok := layout.onPopFinished[viewID]; ok {
|
||||||
session.updateCSSProperty(viewID+"page", "display", "none")
|
session.callFunc("removeView", viewID+"page")
|
||||||
if finished.listener != nil {
|
if finished.listener != nil {
|
||||||
finished.listener(finished.view)
|
finished.listener(finished.view)
|
||||||
}
|
}
|
||||||
|
@ -405,6 +405,115 @@ func transformMirror(transform TransformProperty, session Session) TransformProp
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Append appends a view to the end of the list of a view children
|
||||||
|
func (layout *stackLayoutData) Append(view View) {
|
||||||
|
if view == nil {
|
||||||
|
ErrorLog("StackLayout.Append(nil) is forbidden")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stackID := layout.htmlID()
|
||||||
|
view.setParentID(stackID)
|
||||||
|
|
||||||
|
count := len(layout.views)
|
||||||
|
if count == 0 {
|
||||||
|
layout.views = []View{view}
|
||||||
|
} else {
|
||||||
|
layout.views = append(layout.views, view)
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer := allocStringBuilder()
|
||||||
|
defer freeStringBuilder(buffer)
|
||||||
|
|
||||||
|
buffer.WriteString(`<div id="`)
|
||||||
|
buffer.WriteString(view.htmlID())
|
||||||
|
buffer.WriteString(`page" class="ruiStackPageLayout">`)
|
||||||
|
viewHTML(view, buffer, "")
|
||||||
|
buffer.WriteString(`</div>`)
|
||||||
|
|
||||||
|
session := layout.Session()
|
||||||
|
if count > 0 {
|
||||||
|
session.updateCSSProperty(layout.views[count-1].htmlID()+"page", "visibility", "hidden")
|
||||||
|
}
|
||||||
|
session.appendToInnerHTML(stackID, buffer.String())
|
||||||
|
|
||||||
|
if listener, ok := layout.changeListener[Content]; ok {
|
||||||
|
listener(layout, Content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert inserts a view to the "index" position in the list of a view children
|
||||||
|
func (layout *stackLayoutData) Insert(view View, index int) {
|
||||||
|
if view == nil {
|
||||||
|
ErrorLog("StackLayout.Insert(nil, ...) is forbidden")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if layout.views == nil || index < 0 || index >= len(layout.views) {
|
||||||
|
layout.Append(view)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stackID := layout.htmlID()
|
||||||
|
view.setParentID(stackID)
|
||||||
|
if index > 0 {
|
||||||
|
layout.views = append(layout.views[:index], append([]View{view}, layout.views[index:]...)...)
|
||||||
|
} else {
|
||||||
|
layout.views = append([]View{view}, layout.views...)
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer := allocStringBuilder()
|
||||||
|
defer freeStringBuilder(buffer)
|
||||||
|
|
||||||
|
buffer.WriteString(`<div id="`)
|
||||||
|
buffer.WriteString(view.htmlID())
|
||||||
|
buffer.WriteString(`page" class="ruiStackPageLayout" style="visibility: hidden;">`)
|
||||||
|
viewHTML(view, buffer, "")
|
||||||
|
buffer.WriteString(`</div>`)
|
||||||
|
|
||||||
|
session := layout.Session()
|
||||||
|
session.appendToInnerHTML(stackID, buffer.String())
|
||||||
|
|
||||||
|
if listener, ok := layout.changeListener[Content]; ok {
|
||||||
|
listener(layout, Content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove removes view from list and return it
|
||||||
|
func (layout *stackLayoutData) RemoveView(index int) View {
|
||||||
|
if layout.views == nil {
|
||||||
|
layout.views = []View{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
count := len(layout.views)
|
||||||
|
if index < 0 || index >= count {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
session := layout.Session()
|
||||||
|
view := layout.views[index]
|
||||||
|
view.setParentID("")
|
||||||
|
|
||||||
|
if count == 1 {
|
||||||
|
layout.views = []View{}
|
||||||
|
} else if index == 0 {
|
||||||
|
layout.views = layout.views[1:]
|
||||||
|
} else if index == count-1 {
|
||||||
|
layout.views = layout.views[:index]
|
||||||
|
session.updateCSSProperty(layout.views[count-2].htmlID()+"page", "visibility", "visible")
|
||||||
|
} else {
|
||||||
|
layout.views = append(layout.views[:index], layout.views[index+1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
layout.Session().callFunc("removeView", view.htmlID()+"page")
|
||||||
|
|
||||||
|
if listener, ok := layout.changeListener[Content]; ok {
|
||||||
|
listener(layout, Content)
|
||||||
|
}
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
func (layout *stackLayoutData) Push(view View, onPushFinished func()) {
|
func (layout *stackLayoutData) Push(view View, onPushFinished func()) {
|
||||||
if view == nil {
|
if view == nil {
|
||||||
ErrorLog("StackLayout.Push(nil, ....) is forbidden")
|
ErrorLog("StackLayout.Push(nil, ....) is forbidden")
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (container *viewsContainerData) Views() []View {
|
||||||
return []View{}
|
return []View{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func viewsContainerContentChanged(container *viewsContainerData) {
|
func viewsContainerContentChanged1(container *viewsContainerData) {
|
||||||
updateInnerHTML(container.htmlID(), container.Session())
|
updateInnerHTML(container.htmlID(), container.Session())
|
||||||
if listener, ok := container.changeListener[Content]; ok {
|
if listener, ok := container.changeListener[Content]; ok {
|
||||||
listener(container, Content)
|
listener(container, Content)
|
||||||
|
@ -81,24 +81,37 @@ func (container *viewsContainerData) Append(view View) {
|
||||||
} else {
|
} else {
|
||||||
container.views = append(container.views, view)
|
container.views = append(container.views, view)
|
||||||
}
|
}
|
||||||
viewsContainerContentChanged(container)
|
|
||||||
|
buffer := allocStringBuilder()
|
||||||
|
defer freeStringBuilder(buffer)
|
||||||
|
|
||||||
|
viewHTML(view, buffer, "")
|
||||||
|
container.Session().appendToInnerHTML(htmlID, buffer.String())
|
||||||
|
|
||||||
|
if listener, ok := container.changeListener[Content]; ok {
|
||||||
|
listener(container, Content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert inserts a view to the "index" position in the list of a view children
|
// Insert inserts a view to the "index" position in the list of a view children
|
||||||
func (container *viewsContainerData) Insert(view View, index int) {
|
func (container *viewsContainerData) Insert(view View, index int) {
|
||||||
if view != nil {
|
if view != nil {
|
||||||
htmlID := container.htmlID()
|
|
||||||
if container.views == nil || index < 0 || index >= len(container.views) {
|
if container.views == nil || index < 0 || index >= len(container.views) {
|
||||||
container.Append(view)
|
container.Append(view)
|
||||||
} else if index > 0 {
|
return
|
||||||
view.setParentID(htmlID)
|
}
|
||||||
|
|
||||||
|
htmlID := container.htmlID()
|
||||||
|
view.setParentID(htmlID)
|
||||||
|
if index > 0 {
|
||||||
container.views = append(container.views[:index], append([]View{view}, container.views[index:]...)...)
|
container.views = append(container.views[:index], append([]View{view}, container.views[index:]...)...)
|
||||||
viewsContainerContentChanged(container)
|
|
||||||
} else {
|
} else {
|
||||||
view.setParentID(htmlID)
|
|
||||||
container.views = append([]View{view}, container.views...)
|
container.views = append([]View{view}, container.views...)
|
||||||
viewsContainerContentChanged(container)
|
}
|
||||||
|
updateInnerHTML(htmlID, container.Session())
|
||||||
|
if listener, ok := container.changeListener[Content]; ok {
|
||||||
|
listener(container, Content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,7 +138,11 @@ func (container *viewsContainerData) RemoveView(index int) View {
|
||||||
}
|
}
|
||||||
|
|
||||||
view.setParentID("")
|
view.setParentID("")
|
||||||
viewsContainerContentChanged(container)
|
|
||||||
|
container.Session().callFunc("removeView", view.htmlID())
|
||||||
|
if listener, ok := container.changeListener[Content]; ok {
|
||||||
|
listener(container, Content)
|
||||||
|
}
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue