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

Switch case from conditional statement to determine keyboard width #526

Merged

Conversation

mcrkgus
Copy link
Contributor

@mcrkgus mcrkgus commented Dec 20, 2024

Contributor checklist


Description

Switch from conditional statements to switch and case statements to determine the keyboard width.

switch key {
     case "ABC", "АБВ":
       layer.setValue(true, forKey: "isSpecial")
       widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
    case "#+=", "selectKeyboard":
       layer.setValue(true, forKey: "isSpecial")
       widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarSpecialKeysWidth).isActive = true
     case "delete":
       layer.setValue(true, forKey: "isSpecial")
       widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarDeleteKeyWidth).isActive = true
     case SpecialKeys.capsLock:
       layer.setValue(true, forKey: "isSpecial")
       widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarCapsLockKeyWidth).isActive = true
     case SpecialKeys.indent:
       layer.setValue(true, forKey: "isSpecial")
       widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarIndentKeyWidth).isActive = true
     case "shift" where idx == 0:
       layer.setValue(true, forKey: "isSpecial")
       widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarShiftKeyWidth).isActive = true
     case "shift" where idx > 0:
       layer.setValue(true, forKey: "isSpecial")
       widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarRightShiftKeyWidth).isActive = true
     case "return":
       layer.setValue(true, forKey: "isSpecial")
       widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarReturnKeyWidth).isActive = true
     case "123", ".?123", "return", "hideKeyboard":
       if DeviceType.isPad
           && key == "return"
           && ((commandState != .translate && ["English", "Portuguese", "Italian"].contains(controllerLanguage)) ||
               (commandState == .translate && ["en", "pt", "it"].contains(getControllerTranslateLangCode())))
           && row == 1 {
         layer.setValue(true, forKey: "isSpecial")
         widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1.5).isActive = true
       } else {
         layer.setValue(true, forKey: "isSpecial")
         widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
       }
}

Related issue

@mcrkgus mcrkgus marked this pull request as draft December 20, 2024 02:17
Copy link

github-actions bot commented Dec 20, 2024

Thank you for the pull request!

The Scribe team will do our best to address your contribution as soon as we can. The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the General and iOS rooms once you're in. Also consider joining our bi-weekly Saturday dev syncs. It'd be great to have you!

Maintainer checklist

  • The linting and formatting workflows within the PR checks do not indicate new errors in the files changed

  • The CI unit test workflows within the PR checks do not indicate new errors in the files changed

  • The CHANGELOG has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

First PR Commit Check

  • The commit messages for the remote branch should be checked to make sure the contributor's email is set up correctly so that they receive credit for their contribution
  • The contributor's name and icon in remote commits should be the same as what appears in the PR
  • If there's a mismatch, the contributor needs to make sure that the email they use for GitHub matches what they have for git config user.email in their local Scribe-iOS repo (can be set with git config --global user.email "GITHUB_EMAIL")

@mcrkgus mcrkgus marked this pull request as ready for review December 20, 2024 02:25
@andrewtavis andrewtavis self-requested a review December 20, 2024 07:33
@andrewtavis
Copy link
Member

Thanks much for the PR! Could you do a refactor to make sure that we don't have "return" in two different switch cases, @mcrkgus? We should be good to go at that point :)

@mcrkgus
Copy link
Contributor Author

mcrkgus commented Dec 20, 2024

@andrewtavis
I have revised and reflected the parts you mentioned! Please check. Thank you 😊

@andrewtavis
Copy link
Member

Fantastic, @mcrkgus! I'm for a few days till the 26th, so I won't be able to do a final review until then. @Jag-Marcel, if you have a moment, would you be able to take a look at this? If you're ok with it I can then merge, or feel free to +1 and I'll finalize it when I'm back :)

@mcrkgus, from here you'd be welcome to continue any further work for #399 and #525. What are the next steps you're planning?

@Jag-Marcel
Copy link
Member

I'll take a look tomorrow morning 👍

@Jag-Marcel Jag-Marcel self-requested a review December 22, 2024 08:07
Copy link
Member

@Jag-Marcel Jag-Marcel left a comment

Choose a reason for hiding this comment

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

All looks good to me, works fine on all keyboards still and this is much simpler and easier to read, good work @mcrkgus!
@andrewtavis I think this is good to be merged

@Jag-Marcel
Copy link
Member

@andrewtavis On a more unrelated note, I noticed that on iPad, the key width in landscape is all over the place. If you start a keyboard on landscape, the keys change width slightly when switching from letter keys to symbols. If you start on portrait, all special keys remain weirdly thin in landscape, the regular keys start out normal albeit with more space between them, but when you switch to symbols they are really thin.
This doesn't have anything to do with the changes in this PR I think, it's also a problem on the main branch.

Is there already an issue for this that I missed, or do you want me to make one?

@andrewtavis
Copy link
Member

There's no issue for this so far, @Jag-Marcel :) Would be great if you made one and included some screenshots.

Copy link
Member

@andrewtavis andrewtavis left a comment

Choose a reason for hiding this comment

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

Thanks for the great first contribution, @mcrkgus! Hope we can get another PR from you again soon :) Please let us know what the next steps are for the issues you're working on 😊

@andrewtavis andrewtavis merged commit 006b740 into scribe-org:main Dec 22, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants