Show common user interface elements from Apple TV in your native app using TVUIKit.

Posts under TVUIKit tag

26 Posts

Post

Replies

Boosts

Views

Activity

XCUIElement click event outside of testing framework
I would like to click an element without user input. I see it's possible in XCUIElement which is a part of the XCTest framework to ensure things are working correctly, and I'm aware of various other testing frameworks that support E2E testing with simulated clicks. But is it possible to trigger this in production outside of testing? E.g. How app remotes work for a TV - pressing a button on the app will move right, left, or click an object on the TV (only remove the TV from this question and have it target the OS it's running on)
2
0
1.2k
Jan ’22
tvOS 14 UIBlurEffect crash
I have in my project different code which is responsible for the blur effect in my app. In tvOS 13 this worked fine but in tvOS 14 I have to remove the code otherwise the app will crash. What exactly do I have to change in the code to make it run on tvOS 14. Thanks for the help. private func sharedSetup(effect: UIBlurEffect, radius: CGFloat = 90) {			 let UICustomBlurEffect = NSClassFromString("_UICustomBlurEffect") as! UIBlurEffect.Type let raw = effect.value(forKey: "_style") as! Int let style = UIBlurEffect.Style(rawValue: raw)! let effect = UICustomBlurEffect.init(style: style)						 effect.setValue(1.0, forKey: "scale")		 effect.setValue(radius, forKey: "blurRadius")			 effect.setValue(UIColor.clear, forKey: "colorTint") self.blurEffect = effect	 }
2
0
1.8k
Jan ’22
Is there no way to check in code if the "Focus Style: High Contrast" accessibility setting on tvOS is active?
On tvOS you can choose Settings > Accessibility > Display > Focus Style > High Contrast to have teasers highlighted by a white border when focused: However, I cannot find out how to use this feature on my own custom views. It seems that only TVPosterView makes use of this High Contrast accessibility setting. I'd like to be able to show such a frame on my custom views if this setting is enabled but I cannot find how to check if it's enabled. None of the bools listed on https://developer.apple.com/documentation/uikit/uiaccessibility under Capabilities (like isVoiceOverRunning, isGuidedAccessEnabled, isReduceTransparencyEnabled, etc.) seems to refer to this Focus Style setting. Can anybody point me in the right direction? How do I check in code whether Focus Style is set to High Contrast? How do I get the High Contrast frame on non-TVPosterView views?
1
1
1.3k
Oct ’21
tvOS 15 - Cell registration inside a diffable data source cell provider exception
What follows is about tvOS 15 but may also apply to iOS 15. Our app may display several types of UICollectionView cells and it depends on the content sent by our backend. Prior to tvOS 15, we used to lazily instantiate UICollectionView cell registrations when needed for the first time while building a UICollectionViewDiffableDataSource. Eventually, each cell registration is only instantiated once (or never). Now tvOS 15 throws an exception when doing so, pretending to prevent the app from creating a new cell registration each time. And it does not care whether it's actually a new cell registration each time or one that is lazily instantiated once. Here is the exception: *** Assertion failure in -[UICollectionView dequeueConfiguredReusableCellWithRegistration:forIndexPath:item:], UICollectionView.m:7413 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to dequeue a cell using a registration that was created inside -collectionView:cellForItemAtIndexPath: or inside a UICollectionViewDiffableDataSource cell provider. Creating a new registration each time a cell is requested will prevent reuse and cause created cells to remain inaccessible in memory for the lifetime of the collection view. Registrations should be created up front and reused. Registration: <UICollectionViewCellRegistration: 0x6000000f8c60>' I understand the concern but lazy instantiation is a thing and it should not be for forbidden for the sake of best practices that are not related to it. In my humble opinion, this assert should be removed and apps should be allowed to create cell registrations on the fly.
3
0
2.1k
Sep ’21
TVCollectionViewFullScreenLayout
Hi, I'm having an issue with TVCollectionViewFullScreenLayout. The requirement is that a user can pick from a collection view of items which then presents a new ViewController with a UICollectionView using TVCollectionViewFullScreenLayout populated with cells derived from TVCollectionViewFullScreenCell, with the initial position set to the same item the user selected. Calling collectionView.scrollToItemAt initially works but then it snaps back one position to the previous cell. Simply adding one to the index position leaves the user with an ugly animation as the view loads and then scrolls to the correct position. I investigated the .centerIndexPath property but this is get only. An example of the correct behaviour can be found in the TV app when selecting a title from a horizontal list of suggestions. The view that is presented starts with the item the user selected.
3
0
1.7k
Sep ’21
Arrow Buttons cause UIScrollView to scroll after being held down
I have been testing out an existing app with the new Apple TV 4K (2nd generation) - the one with the new remote - and there seems to be a new behavior implemented with this new remote. If you have focusable content (let's say a custom list) in a UIScrollView, and the user presses and holds one of the up/down/left/right buttons around the touch-pad, the focus engine will start by moving focus in the direction of the arrow button being held down - one-by-one, as expected, however, after a certain amount of time, the focus is removed and the view simply starts slowly scrolling and no more focus events are called. Is there a way to prevent this behavior from happening, and simply have arrow buttons move focus (even after being held down)? How do I know that the UIScrollView has entered into this special state of auto-scrolling while the arrow button is held down? None of the UIScrollViewDelegate methods seem to cover this use-case. I have tried disabling the panGestureRecognizer associated with the UIScrollView but that doesn't work. I am not sure how to implement this new type of UIScrollView - I was never expecting focus to be removed without the next item receiving focus.
0
0
1.2k
Jul ’21
XCUIElement click event outside of testing framework
I would like to click an element without user input. I see it's possible in XCUIElement which is a part of the XCTest framework to ensure things are working correctly, and I'm aware of various other testing frameworks that support E2E testing with simulated clicks. But is it possible to trigger this in production outside of testing? E.g. How app remotes work for a TV - pressing a button on the app will move right, left, or click an object on the TV (only remove the TV from this question and have it target the OS it's running on)
Replies
2
Boosts
0
Views
1.2k
Activity
Jan ’22
tvOS 14 UIBlurEffect crash
I have in my project different code which is responsible for the blur effect in my app. In tvOS 13 this worked fine but in tvOS 14 I have to remove the code otherwise the app will crash. What exactly do I have to change in the code to make it run on tvOS 14. Thanks for the help. private func sharedSetup(effect: UIBlurEffect, radius: CGFloat = 90) {&#9;&#9;&#9; let UICustomBlurEffect = NSClassFromString("_UICustomBlurEffect") as! UIBlurEffect.Type let raw = effect.value(forKey: "_style") as! Int let style = UIBlurEffect.Style(rawValue: raw)! let effect = UICustomBlurEffect.init(style: style)&#9;&#9;&#9;&#9;&#9;&#9; effect.setValue(1.0, forKey: "scale")&#9;&#9; effect.setValue(radius, forKey: "blurRadius")&#9;&#9;&#9; effect.setValue(UIColor.clear, forKey: "colorTint") self.blurEffect = effect&#9; }
Replies
2
Boosts
0
Views
1.8k
Activity
Jan ’22
Is there no way to check in code if the "Focus Style: High Contrast" accessibility setting on tvOS is active?
On tvOS you can choose Settings > Accessibility > Display > Focus Style > High Contrast to have teasers highlighted by a white border when focused: However, I cannot find out how to use this feature on my own custom views. It seems that only TVPosterView makes use of this High Contrast accessibility setting. I'd like to be able to show such a frame on my custom views if this setting is enabled but I cannot find how to check if it's enabled. None of the bools listed on https://developer.apple.com/documentation/uikit/uiaccessibility under Capabilities (like isVoiceOverRunning, isGuidedAccessEnabled, isReduceTransparencyEnabled, etc.) seems to refer to this Focus Style setting. Can anybody point me in the right direction? How do I check in code whether Focus Style is set to High Contrast? How do I get the High Contrast frame on non-TVPosterView views?
Replies
1
Boosts
1
Views
1.3k
Activity
Oct ’21
tvOS 15 - Cell registration inside a diffable data source cell provider exception
What follows is about tvOS 15 but may also apply to iOS 15. Our app may display several types of UICollectionView cells and it depends on the content sent by our backend. Prior to tvOS 15, we used to lazily instantiate UICollectionView cell registrations when needed for the first time while building a UICollectionViewDiffableDataSource. Eventually, each cell registration is only instantiated once (or never). Now tvOS 15 throws an exception when doing so, pretending to prevent the app from creating a new cell registration each time. And it does not care whether it's actually a new cell registration each time or one that is lazily instantiated once. Here is the exception: *** Assertion failure in -[UICollectionView dequeueConfiguredReusableCellWithRegistration:forIndexPath:item:], UICollectionView.m:7413 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to dequeue a cell using a registration that was created inside -collectionView:cellForItemAtIndexPath: or inside a UICollectionViewDiffableDataSource cell provider. Creating a new registration each time a cell is requested will prevent reuse and cause created cells to remain inaccessible in memory for the lifetime of the collection view. Registrations should be created up front and reused. Registration: <UICollectionViewCellRegistration: 0x6000000f8c60>' I understand the concern but lazy instantiation is a thing and it should not be for forbidden for the sake of best practices that are not related to it. In my humble opinion, this assert should be removed and apps should be allowed to create cell registrations on the fly.
Replies
3
Boosts
0
Views
2.1k
Activity
Sep ’21
TVCollectionViewFullScreenLayout
Hi, I'm having an issue with TVCollectionViewFullScreenLayout. The requirement is that a user can pick from a collection view of items which then presents a new ViewController with a UICollectionView using TVCollectionViewFullScreenLayout populated with cells derived from TVCollectionViewFullScreenCell, with the initial position set to the same item the user selected. Calling collectionView.scrollToItemAt initially works but then it snaps back one position to the previous cell. Simply adding one to the index position leaves the user with an ugly animation as the view loads and then scrolls to the correct position. I investigated the .centerIndexPath property but this is get only. An example of the correct behaviour can be found in the TV app when selecting a title from a horizontal list of suggestions. The view that is presented starts with the item the user selected.
Replies
3
Boosts
0
Views
1.7k
Activity
Sep ’21
Arrow Buttons cause UIScrollView to scroll after being held down
I have been testing out an existing app with the new Apple TV 4K (2nd generation) - the one with the new remote - and there seems to be a new behavior implemented with this new remote. If you have focusable content (let's say a custom list) in a UIScrollView, and the user presses and holds one of the up/down/left/right buttons around the touch-pad, the focus engine will start by moving focus in the direction of the arrow button being held down - one-by-one, as expected, however, after a certain amount of time, the focus is removed and the view simply starts slowly scrolling and no more focus events are called. Is there a way to prevent this behavior from happening, and simply have arrow buttons move focus (even after being held down)? How do I know that the UIScrollView has entered into this special state of auto-scrolling while the arrow button is held down? None of the UIScrollViewDelegate methods seem to cover this use-case. I have tried disabling the panGestureRecognizer associated with the UIScrollView but that doesn't work. I am not sure how to implement this new type of UIScrollView - I was never expecting focus to be removed without the next item receiving focus.
Replies
0
Boosts
0
Views
1.2k
Activity
Jul ’21