fuse-open / fuselibs

Fuselibs is the Uno-libraries that provide the UI framework used in Fuse apps
https://npmjs.com/package/@fuse-open/fuselibs
MIT License
176 stars 72 forks source link

Manipulating Each.Offset and Limit gives unexpected results #714

Open Sunjammer opened 6 years ago

Sunjammer commented 6 years ago

Fuse 1.3.2

<App>
    <JavaScript>
        const O = require("FuseJS/Observable")
        const offset = O(0)

        let items = []
        for(let i = 20; i--;)
            items[i] = {color:[Math.random(), Math.random(), Math.random()]}

        module.exports = {
            items,
            offset,
            limit : offset.map(value => Math.max(0, Math.min(items.length-value, 10))),
            next : () => {
                offset.value++
                if(offset.value>=items.length)
                    offset.value = 0
            }
        }
    </JavaScript>

    <Text Value="Offset: {offset} Limit: {limit}"/>
    <Viewport Perspective="1.7" PerspectiveRelativeTo="Width">
        <Panel>
            <Rotation DegreesY="20"/>
            <Each Items="{items}" Offset="{offset}" Limit="{limit}">
                <Rectangle Width="200" Height="200" Color="{color}" >
                    <Text Value="{= index()}"/>
                    <Translation Z="(index() - {offset}) * 20"/>
                </Rectangle>
            </Each>
        </Panel>
    </Viewport>
    <Tapped Handler="{next}"/>
</App>

In this example I'm expecting the stack to shorten as the offset approaches the end and the limit decreases. Instead I get this and I don't understand why:

awaaa

mortoray commented 6 years ago

You don't need to constraint Limit on your own, Each will not inlucde more items than it has.

mortoray commented 6 years ago

This doesn't happen on fuselibs/master, it behaves like you'd expect. There is just a minor issue of it pushing the stack forward one as you exceed 10 Offset, but this might be from the JS code itself.

Where are you seeing this issue?

Sunjammer commented 6 years ago

This was in public Fuse 1.3.2, i'll try the latest release

Sunjammer commented 6 years ago

Yep, happens in 1.4 public as well

Sunjammer commented 6 years ago

Leaving Limit hard coded to 10 changes nothing, once the offset exceeds 10 elements are no longer removed.

mortoray commented 6 years ago

Are you viewing in Preview?

Sunjammer commented 6 years ago

Yes

kusma commented 6 years ago

Then this is likely due to one of the many corner-cases around previews template-handling.

Sunjammer commented 6 years ago

Happens in release build for android too