Giter Site home page Giter Site logo

andrexpmt's People

Watchers

 avatar  avatar

andrexpmt's Issues

Drag and drop bug

To run the app just press the play button in intellij.
Im using the android 30 image in the emulator, but the jetpack compose preview feature also exhibits the below behaviour, you just cant run the debugger against that IIUC.

The drag and drop code is from

https://www.youtube.com/watch?v=ST99k8qK6SM
(Android Drag and Drop in Jetpack Compose (with Animation) - Android Studio Tutorial with Kotlin)
(K Apps, Matthias Kerat, 2022)
https://github.com/MatthiasKerat/DragAndDropYT/tree/main

Problem description

Hi folks, I'm doing a homework project in jetpack compose and I have a bug I havent been able to track down after hours of debugging. I only have a basic knowledge of jetpack; the issue is that I'm either getting some stale, or refreshed data in a lambda closure in a composable, I cant tell.

i.e. dataToDrop is wrong in this scope, but everywhere else I've managed to look in the debugger, at any given time the data seems to be correct (except when this code runs):

detectDragGestures(onDragStart = {
viewModel.startDragging()
currentState.dataToDrop = dataToDrop
currentState.isDragging = true
currentState.dragPosition = currentPosition + it
currentState.draggableComposable = content

It's passed here:


and I would hope it is a constant reference to the appropriate LetterTileModel object.

I'm trying to drag and drop some tiles onto a game grid, and the drag operation passes a tile model object around, I have a "list" of tiles the user can drag from, and that works fine-ish; when I take a tile out of the list and put it on the grid, the remaining tiles get relabeled just fine, however somehow the stored drop data (the internal identity of the tile) somehow retains the original ordering, and I find this completely incomprehensible.

So if my tiles are [ H Y D P E ] and I take out H and put it on the grid, the remaining tiles show as [ Y D P E ] but their identities are [ H Y D P ], or at least debugging shows that when picking up the remaining tile, the onDrag data will have the labels H Y D P respectively. Placing the Y tile will result in a crash because the "owner" of the H tile is now a TileSocket which doesnt implement move(), and move() is called on the owner.

(This results in various odd behaviors such as the fact that placing every other tile will work (presumably because the incrementing off-by-one issue will not have assigned an already placed identity to the tile yet))

The specific issue is that the dataToDrop argument passed through DropTarget to the onDrag callback is the wrong offset list data (but I don't understand how it can end up like that)

The game crashes when placing a tile located after a previously placed tile because the "owner" of the previous tile is now a socket, which doesn't implement move() and throws a TODO() exception, but the actual problem is that the identity of the second tile refers to the first tile's identity, and not that the exception happens

Sidestepping the exception results in placing the identity of the first tile any number of times
(because its not removing the new tile from the playable tile set)

(I don't understand how the displaying list can be correct, but the identities can be offset, when Im not doing any sort of mutation on which tile has which identity, and I don't even have a data structure that manages that as an aggregate, its assigned to tiles individually...I think.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.