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

iOS clock animations on homescreen widget #1

Closed
liudhzhyym opened this issue Feb 19, 2021 · 3 comments
Closed

iOS clock animations on homescreen widget #1

liudhzhyym opened this issue Feb 19, 2021 · 3 comments

Comments

@liudhzhyym
Copy link

I want to add a homescreen widget to my app, just like the iOS system Clock app, the second hand keeps moving every second. I have been searching on Google and Github for a long time and have not found a suitable solution. I have seen that there are already third-party apps that can implement such desktop widgets.

Do you know how do they do it?

@mromanuk
Copy link

I want to add a homescreen widget to my app, just like the iOS system Clock app, the second hand keeps moving every second. I have been searching on Google and Github for a long time and have not found a suitable solution. I have seen that there are already third-party apps that can implement such desktop widgets.

Do you know how do they do it?

I saw the same, I'm building a Widget App and I would like to have the sub second hand on my clock. Did you find out?

@pawello2222
Copy link
Owner

pawello2222 commented Feb 28, 2021

@liudhzhyym @mromanuk Thanks for the question.

According to Apple it can't be done.

Here you can find a comment made by a Systems Engineer from Apple:

[...] However, you cannot update views to the time other than the relative date text label. So you cannot replicate the Clock widget for example and have second hands on a clock tick by while the widget is visible. Sorry.

Also, from the Human Interface Guidelines for Widgets:

Keep your widget up-to-date. To remain relevant and useful, widgets should periodically refresh their information. Widgets don’t support continuous, real-time updates, and the system may adjust the limits for updates depending on various factors.

My understanding is that the only way for third-party apps to provide such animations is to use private API. The system Clock Widget does this after all, so it might actually be possible to replicate this behaviour using some private methods that I'm not aware of.

I didn't really look into it myself yet (will probably do when I have more time) but in the meantime you can see this post for a starter:

@pawello2222
Copy link
Owner

@liudhzhyym @mromanuk

It looks like the private method you were looking for is _clockHandRotationEffect:

extension SwiftUI.View {
  @available(iOS 14.0, macOS 11, *)
  @available(tvOS, unavailable)
  @available(watchOS, unavailable)
  public func _clockHandRotationEffect(_ period: WidgetKit._ClockHandRotationEffect.Period, in timeZone: Foundation.TimeZone, anchor: SwiftUI.UnitPoint = .center) -> some SwiftUI.View
}

If you'd like to investigate it more, this code can be found in the WidgetKit framework module.

As I mentioned in the post above, the whole tutorial can be found here:

And here's the path to the original WidgetKit module:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/WidgetKit.framework/Modules/WidgetKit.swiftmodule

Please bear in mind that this is a private method and not approved by Apple - it may stop working any time or your app might be rejected (even after initially approved).

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

No branches or pull requests

3 participants