Skip to content

fix(treatments): keep focused input visible above the keyboard - #1238

Open
Sjoerd-Bo3 wants to merge 1 commit into
nightscout:devfrom
Sjoerd-Bo3:claude/issue-1115-upstream
Open

fix(treatments): keep focused input visible above the keyboard#1238
Sjoerd-Bo3 wants to merge 1 commit into
nightscout:devfrom
Sjoerd-Bo3:claude/issue-1115-upstream

Conversation

@Sjoerd-Bo3

Copy link
Copy Markdown
Contributor

The treatments entry list relies on the system's default keyboard avoidance to keep the focused field visible. This is unreliable: the list height changes with user settings (e.g. the Reduced Bolus / Super Bolus toggles add a row), and on some devices the bolus field ends up hidden behind the keyboard. A user can then type "11" instead of "1" without seeing it, which is a safety concern.

Wrap the list in a ScrollViewReader and explicitly scroll the focused input row into view (centered above the keyboard) whenever focus changes, so the user can always see what they are entering regardless of which optional rows are shown.

Fixes #1115

The treatments entry list relies on the system's default keyboard
avoidance to keep the focused field visible. This is unreliable: the
list height changes with user settings (e.g. the Reduced Bolus / Super
Bolus toggles add a row), and on some devices the bolus field ends up
hidden behind the keyboard. A user can then type "11" instead of "1"
without seeing it, which is a safety concern.

Wrap the list in a ScrollViewReader and explicitly scroll the focused
input row into view (centered above the keyboard) whenever focus
changes, so the user can always see what they are entering regardless of
which optional rows are shown.

Fixes nightscout#1115
@Sjoerd-Bo3

Copy link
Copy Markdown
Contributor Author

@LiroyvH olease stamp this with a approval if it works

@EJM0

EJM0 commented Jun 26, 2026

Copy link
Copy Markdown

While the issue was also present in the local iPhone 16 Pro SIM, defining a separate .safeAreaPadding(.bottom: 50) for the List at line 398 seems to fix this. Also, this elevates the text input a bit further from the keyboard close button. Seems to be device consistent, see screenshots of iPhone 16 Pro SIM and iPhone 17 Pro.
Maybe the padding could be increased even more to circumvent miss clicks on the close button of the keyboard.

I only tested this for the 16 and 17 pro so i don't know if that fix is also consistent on smaller iPhone models, here maybe the original fix of @Sjoerd-Bo3 would be better.
But i think adding the specific .safeAreaPadding triggers iOS to definitely keep the safe area for focused fields....

16:
image
17:
image

@Sjoerd-Bo3

Copy link
Copy Markdown
Contributor Author

Defining a pixelike area is tricky when dealing with a lot of devices and aspect ratios. It will not work somewhere. So thats why I went the builtin way instead of that. I agree, yours looks cleaner on your device, but that may vary unfortunately...

@EJM0

EJM0 commented Jun 26, 2026

Copy link
Copy Markdown

Okay good to know. That's where I did not knew, if these type of areas are consistent for different devices.Considering that using a scrollview is way more consistent. 👍

@Sjoerd-Bo3

Copy link
Copy Markdown
Contributor Author

Could be, but you are hand defining that 50px, so that probably doesnt scale i GUESS..

@LiroyvH

LiroyvH commented Jun 26, 2026

Copy link
Copy Markdown
Member

@EJM0 With it scrolled down as like in your screenshot, you cannot see the warning text for dangerous low glucose as its dropped behind the keyboard. Enter a high amount of units (without carbs to compensate) to see what I mean.

@dnzxy

dnzxy commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Since this is entirely vibed, before I spend time reviewing it:
@LiroyvH @EJM0 does this work?

@LiroyvH

LiroyvH commented Jul 6, 2026

Copy link
Copy Markdown
Member

@dnzxy

Since this is entirely vibed, before I spend time reviewing it: @LiroyvH @EJM0 does this work?

The first version (cfe02c5 or a42620e depending on where you look) works, yup - have been using it ever since (also in latest dev, 112fe88). Screenshots are here: #1115 (comment)

The second version (I think 810da2a) didn't work and actually made matters worse. I see now there appears to be another modification shown here in this PR, 5add693, that I have not tested and I'm not sure which iteration (1st or 2nd) it augments. Seems to be a minor modification but I'm unsure to what and which version.

Unfortunately I'm not quite able to tell which version actually ended up being submitted for PR now... Sorry. Hopefully @Sjoerd-Bo3 can clarify that.

Sorry for being vague but I'm not entirely sure which one has been submitted. if it's the first version then I can confirm it works fine. Any other version: I'd have to testdrive it.

@dnzxy

dnzxy commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for adding some context @LiroyvH .
@Sjoerd-Bo3 please clean up the PR and then let's get it tested one more round.

@Sjoerd-Bo3
Sjoerd-Bo3 force-pushed the claude/issue-1115-upstream branch from 5add693 to cfe02c5 Compare July 7, 2026 05:07
@Sjoerd-Bo3

Copy link
Copy Markdown
Contributor Author

Version 1/3 were the same, cleaned up the PR and removed commit 2/3. So we are back where @LiroyvH and I tested for 2 weeks.

@LiroyvH

LiroyvH commented Jul 12, 2026

Copy link
Copy Markdown
Member

@Sjoerd-Bo3 @dnzxy It would seem the latest dev version fails to build with these changes.
Scherm­afbeelding 2026-07-12 om 23 43 56

To exclude this as the culprit:

  • Cloned a fresh copy of Trio dev and made no modifications: build succeeds.
  • Clean build folder, close XCode, replace TreatmentsRootView.swift with the version from this PR and go again: build fails again.

It built fine before this, but I cannot get it to build this at all anymore with the latest dev version.

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.

5 participants