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

feat(toggle): add iOS 18 haptic feedback #29945

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jedlikowski
Copy link

Issue number: resolves #29942


What is the current behavior?

Safari on iOS doesn't support vibration API and it might never do: WebKit/standards-positions#267. However, as described in the issue, since iOS 18 we can use a special <input type=checkbox switch> element to bring haptic feedback to PWAs by triggering a click on this input's label.

What is the new behavior?

  • in iOS mode, we render a hidden <label> with <input type=checkbox switch> inside
  • when Toggle changes checked state, we programatically trigger click on the special label
  • we don't care about synchronisation of checked state to that haptic-only element, we just need to toggle it.

Does this introduce a breaking change?

  • Yes
  • No

Other information

No visual changes, just slight haptic feedback when changing Toggle state on iOS 18+

Copy link

vercel bot commented Oct 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ionic-framework ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 6:26am

@@ -312,7 +343,8 @@ export class Toggle implements ComponentInterface {
[`toggle-${rtl}`]: true,
})}
>
<label class="toggle-wrapper">
{this.renderFallbackHapticElements()}
<label class="toggle-wrapper" onClick={this.onClick}>
Copy link
Author

@jedlikowski jedlikowski Oct 17, 2024

Choose a reason for hiding this comment

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

onClick listener moved to label, without this change Host was capturing clicks on the haptic <label> too, not only on .toggle-wrapper

const { inputId } = this;
const mode = getIonMode(this);

if (hapticAvailable() || mode !== 'ios') {
Copy link
Author

Choose a reason for hiding this comment

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

If I understand correctly, we don't need these elements if Vibration API is available, because then hapticSelection() will work.

@OS-pedrolourenco OS-pedrolourenco requested review from thetaPC and removed request for OS-pedrolourenco October 17, 2024 09:12
@jedlikowski
Copy link
Author

Hi @thetaPC, could you take a look? Do you have any suggestions? Or can we get this merged? Can't wait to have haptic feedback on toggles in my PWA 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add haptic feedback to Toggle in Safari on iOS 18+
1 participant