-
Notifications
You must be signed in to change notification settings - Fork 6
Forms
: Add attachment fixes
#425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forms
: Add attachment fixes
#425
Conversation
…rename-attachments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, just one suggestion to simplify the mapping of FormAttachment to FormAttachmentState.
@@ -80,7 +82,7 @@ internal class AttachmentElementState( | |||
/** | |||
* The attachments associated with the form element. | |||
*/ | |||
val attachments = SnapshotStateList<FormAttachmentState>() | |||
var attachments by mutableStateOf(emptyMap<Int, FormAttachmentState>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FormAttachments are unique, persistent, and implement equals and hashCode. You can key on them, and if that doesn't work there is likely a bug somewhere.
var attachments by mutableStateOf(emptyMap<Int, FormAttachmentState>()) | |
var attachments by mutableStateOf(emptyMap<FormAttachment, FormAttachmentState>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should work too, but it the adds a FormAttachment
dependency to the AttachmentFormElement
. This would mean previews cannot be generated with a list of attachments.
@Composable
AttachmentFormElement(
..
attachments: Map<FormAttachment, FormAttachmentState>,
..
)
Summary of changes
Issue
FormAttachmentState
list is rebuilt after callingfetchAttachments
and hence any previous UI state is lost.FormAttachmentState
objects after a call tofetchAttachments
.Dialog
where the state object can be empty.