Skip to content

Commit

Permalink
feat: adds ability to update list content via a ListContent.version f…
Browse files Browse the repository at this point in the history
…ield
  • Loading branch information
georgejecook committed Aug 5, 2021
1 parent 6283bc3 commit a26ed22
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 67 deletions.
4 changes: 4 additions & 0 deletions src/components/ml/list/models/ListContent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<field
id='isHidden'
type='boolean' />
<field
id='version'
type='integer'
value='0' />

</interface>

Expand Down
2 changes: 2 additions & 0 deletions src/source/ml/BaseRow.bs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ namespace ml
m.log.info("onContentChange")
if m.isInitialized
if m._content = invalid or not m._content.isSameNode(m.content)
'was no content or it changed
m._content = m.content
m.settings = ml.listMixin.getRowSettings(m.owner.content, m._content)
m.onContentChange(m._content)
else if m._content <> invalid
'is the same content
isListRefreshNeeded = false

if m.wasHidden <> m._content.isHidden
Expand Down
6 changes: 3 additions & 3 deletions src/source/ml/HorizontalRow.bs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ namespace ml
m.header = m.componentPool@.getComponent(headerSettings.compName, 1)

if m.header <> invalid
m.header.id = "header"
if headerSettings.position = "onTop"
m.foregroundGroup.appendChild(m.header)
else if headerSettings.position = "underneath"
Expand All @@ -188,8 +187,9 @@ namespace ml

private function cleanHeader()
if m.header <> invalid
m.componentPool@.releaseComponents(m.header)
m.header.getParent().removeChild(m.header)
m.log.info("cleaning header")
m.header@.setContent(invalid)
m.componentPool@.releaseComponent(m.header)
m.header = invalid
m.currentHeaderType = invalid
end if
Expand Down
6 changes: 3 additions & 3 deletions src/source/ml/ItemScroller.bs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace ml
public lastRCMap = {}
public nextRCMap = {}
public index = 0
public focusedItem as mc.types.node
public indexPosition = 0
public focusedIndex = 0
public nextIndex = 0
Expand Down Expand Up @@ -278,9 +279,6 @@ namespace ml
m.container.translation = targetTranslation
'TODO -check if jump is bigger than a certain amount
' m.viewManager.updateRenderedComponents(m.direction, m.index)
if m.isList
? ":1111 "; index
end if
' m.setNextIndex(index)
m.viewManager.updateRenderedComponents(m.direction, index)
' m.setFocusIndex(index, false)
Expand Down Expand Up @@ -495,6 +493,8 @@ namespace ml
m.setNextIndex(m.index + m.direction)
end if

m.focusedItem = m.viewManager.visibleItems[index]

#if use_debug_hacks
mioc.setInstance("_index", m.index)
mioc.setInstance("_nextIndex", m.nextIndex)
Expand Down
12 changes: 6 additions & 6 deletions src/source/ml/ItemViewManager.bs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace ml
end function

public function reset()
m.log.info ("resetting base.itemViewManager", m.__classname)
m.content = invalid
m.components = []
m.rects = []
Expand Down Expand Up @@ -110,6 +111,10 @@ namespace ml
end if
end function

'call this method when the content has changed in some way
function onContentUpdated()
end function

function _createRenderers(content as mc.types.node) as boolean
m.components = []
m.visibleComponents = []
Expand All @@ -121,17 +126,11 @@ namespace ml
protected function onRenderersCreated()
m.isRendering = false
m._updateLayout()
m.numberOfItems = m.visibleItems.count()
end function

function _updateLayout()
m.log.info("_updateLayout")
m.updateScreenRect()

m.visibleComponents = []
m.visibleItems = []
m.rects = []

m.updateLayout()
end function

Expand Down Expand Up @@ -417,6 +416,7 @@ namespace ml

function getRect(index as integer, useScreenCoords = false as boolean)
rect = m.rects[index]

if rect <> invalid
screenRect = {
size: [rect.size[0], rect.size[1]]
Expand Down
19 changes: 16 additions & 3 deletions src/source/ml/List.bs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,25 @@ namespace ml

private function onContentChange()
m.log.info("onContentChange")
if m.isInitialized and (m._content = invalid or not m._content.isSameNode(m.content))
m._content = m.content
m.resetState()
if m.isInitialized
if m._content <> invalid and not m._content.isSameNode(m.content)
m.unobserveNodeField(m._content, "version", m.onContentUpdated)
end if
if m._content = invalid or not m._content.isSameNode(m.content)
m._content = m.content
m.observeNodeField(m._content, "version", m.onContentUpdated, "none")
m.resetState()
else
' m.log.info("current content has changed in some way!")
end if
end if
end function

private function onContentUpdated()
m.log.info("This content has changed in some way")
m.viewManager.onContentUpdated()
end function

private function onAnimateToRowIndexChange(index as integer)
if m.content <> invalid and index <> -1
m.itemScroller.moveToIndex(index)
Expand Down

0 comments on commit a26ed22

Please sign in to comment.