Skip to content
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

Add TextField, SecureField, and a progress document #116

Merged
merged 9 commits into from Jun 29, 2020

Conversation

j-f1
Copy link
Member

@j-f1 j-f1 commented Jun 28, 2020

Currently, it seems that changing the text binding doesn’t actually affect the rendered input. I’m not sure why this happens, but I’m guessing it’s because the value attribute isn’t being set as <input>.value.

I’ve added two TextFields to the demo, which are supposed to have their values synced. Pressing enter in the second one will increment the commit counter.

@j-f1
Copy link
Member Author

j-f1 commented Jun 28, 2020

Looks like Danger is failing at least because it can’t access the GitHub token since this PR comes from a fork.

@MaxDesiatov
Copy link
Collaborator

Thanks for the PR, I'll have a look a bit later today! danger-lint failing is a known issue, I'll turn it off in main so that this doesn't confuse anyone anymore.

@MaxDesiatov MaxDesiatov added the SwiftUI compatibility Tokamak API differences with SwiftUI label Jun 28, 2020
progress.md Outdated
@@ -0,0 +1,137 @@
)# Progress
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a file I should've created from the start, thank you for doing this! Could you also create a docs directory and move it there? Also, seems that ) in the beginning is not needed:

Suggested change
)# Progress
# Progress

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How detailed should this be? I originally had it in a list format which could’ve displayed individual method names but I figured the table would give people a good overview of what is usable and where they can jump in.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, what is currently there already looks great. Maybe I'd tweak table headers, they look kind of weird as empty thin rows, but don't sweat it. I think the API comparison should be automated at some point, but for the list of basic fundamental views this should be more than enough from my perspective, unless you think otherwise.

Hey @carson-katri, I'd be happy to hear your opinion on this, what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can explore an automated approach. In the meantime, you could do the table with HTML to get rid of the header if you wanted to fix them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think headers are that important, so wouldn't mind if they are kept as is in this PR.

@MaxDesiatov
Copy link
Collaborator

I think the text binding issues may be caused by bugs in the State/Binding code, investigating now...

@MaxDesiatov
Copy link
Collaborator

Turns out it's not a state/binding issue, but a more prosaic oversight that's fixed in #117.

@MaxDesiatov MaxDesiatov changed the title Add TextField Add TextField and a progress document Jun 28, 2020
@j-f1
Copy link
Member Author

j-f1 commented Jun 28, 2020

Is there a way to hook into the update function? I need to update the actual value property of the input element, not the value attribute.

@MaxDesiatov
Copy link
Collaborator

Is there a signifcant difference? I've tested your branch locally with #117 applied on top of it and it worked, or am I missing something?

@j-f1
Copy link
Member Author

j-f1 commented Jun 28, 2020

If you type in both fields they will stop updating.

@MaxDesiatov
Copy link
Collaborator

huh, good point, on it...

@MaxDesiatov
Copy link
Collaborator

I updated #117 to update properties, not attributes, so should work now when combined with this PR.

@j-f1
Copy link
Member Author

j-f1 commented Jun 29, 2020

Is it intentional that VStack can have a max of 10 children?

@j-f1
Copy link
Member Author

j-f1 commented Jun 29, 2020

Updated. Note that the newly added text field is still editable despite that not being the intention.

@carson-katri
Copy link
Member

carson-katri commented Jun 29, 2020

@j-f1 This is a limitation of the ViewBuilder, and is present in SwiftUI as well. ViewBuilder takes in arguments and builds a TupleView which is generated to have up to 10 children via buildBlock functions. If you use ForEach or a Group you can go past that limit.

@j-f1
Copy link
Member Author

j-f1 commented Jun 29, 2020

OK cool I reviewed native SwiftUI and the text field’s behavior is the same there 🤷

@j-f1
Copy link
Member Author

j-f1 commented Jun 29, 2020

I tried to implement the other TextField initializer but it looks like Foundation (and therefore the required Formatter) are not yet available?

@j-f1 j-f1 changed the title Add TextField and a progress document Add TextField, SecureField, and a progress document Jun 29, 2020
@j-f1
Copy link
Member Author

j-f1 commented Jun 29, 2020

I dislike the way the SecureField is largely a copy-paste of TextField but I can’t think of a better way since you can’t extend structs.

@carson-katri
Copy link
Member

Could you do a protocol that has all the fields and a isSecure flag?

@MaxDesiatov
Copy link
Collaborator

Foundation is available if you build the package in a special way, but I'd like to avoid it as much as possible. It's a huge dependency, and I'm afraid that even when SwiftWasm has dead code elimination working properly, I'm not sure we'll be able to strip out unused bits of Foundation cleanly, especially due to how big it is and how it also proxies a lot of stuff to CoreFoundation. On the other hand, without Foundation we won't get the Date type, which would be frustrating.

We need to tweak carton so that it links Foundation automatically, but I think for now, please leave out the bits that require Foundation, and maybe add a comment about what's missing.

@j-f1
Copy link
Member Author

j-f1 commented Jun 29, 2020

Could you do a protocol that has all the fields and a isSecure flag?

I gave that a try and it didn’t cut down on the duplication a ton.

commitAction = onCommit
}

// Currently missing feature: use a Formatter to control the value of the TextField
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think it would make sense to highlight this with a FIXME.

Suggested change
// Currently missing feature: use a Formatter to control the value of the TextField
// FIXME:
// Currently missing feature: use a Formatter to control the value of the TextField

Copy link
Collaborator

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM other than a missing FIXME. I agree that SecureField and TextField renderer bits generalized with a protocol probably won't save enough lines of code, but I don't have a strong opinion on whether that protocol should exist, I'll defer to @carson-katri as he suggested it 🙂

@carson-katri
Copy link
Member

SwiftUI doesn't use a protocol, and if it's good enough for Apple then it's good enough for me 😄

@j-f1 j-f1 marked this pull request as ready for review June 29, 2020 16:13
Copy link
Collaborator

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! There's also a conflict in Sources/TokamakDemo/main.swift to be resolved.

Copy link
Collaborator

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit 👍

@MaxDesiatov MaxDesiatov merged commit b2b5ec2 into TokamakUI:main Jun 29, 2020
@j-f1 j-f1 deleted the text-field branch June 29, 2020 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SwiftUI compatibility Tokamak API differences with SwiftUI
Development

Successfully merging this pull request may close these issues.

None yet

3 participants