asynchrony / re-lax Goto Github PK
View Code? Open in Web Editor NEWRecreating Parallax on tvOS
License: MIT License
Recreating Parallax on tvOS
License: MIT License
Amazing product, thank you for your contribution to the world of tvOS ๐
One thing that took me a little bit to figure out, might be good to put it in your docs or something, but this is an example of how you would make this work in Interface Builder:
// Stub container
class SimpleParallaxContainer: UIView, ParallaxContainer {
func focusChanged(_ focus: ParallaxFocusState) {}
func parallaxShadow(forFocus: ParallaxFocusState, defaultShadow: Shadow) -> Shadow? {
return defaultShadow
}
}
// Because ParallaxView doesn't implement initWith(coder:) you can't place it in Interface Builder.
// This UIView subclass substitutes itself with a ParallaxView at runtime.
class ParallaxPlaceholder: UIView {
override func layoutSubviews() {
super.layoutSubviews()
guard let sup = self.superview else { return } // make sure we have a superview
// Create a container
let cont = SimpleParallaxContainer.init(frame: self.bounds)
// Move all of the placeholder's subviews into the container
self.subviews.forEach { (view) in
let f = view.frame
view.removeFromSuperview()
cont.addSubview(view)
view.frame = f
}
// Create a parallax view, using the container we just built
let pView = ParallaxView<SimpleParallaxContainer>(layerContainer: cont)
// Remove ourselves from the view hierarchy and replace with the parallax view
sup.insertSubview(pView, aboveSubview: self)
pView.frame = self.frame
self.removeFromSuperview()
}
}
Definitely no problem if I'm going about this wrong and you feel like pointing it out. Either way, thanks again!
In tvOS 13.4+ and 14.0 Beta, there are much stricter memory limits on top shelf extensions. The example seems to use a lot of memory and gets killed, but that can be fixed as so:
--- a/ReLaxExample/ReLaxTopShelfExample/ServiceProvider.swift
+++ b/ReLaxExample/ReLaxTopShelfExample/ServiceProvider.swift
@@ -8,7 +8,7 @@ class ServiceProvider: NSObject, TVTopShelfProvider {
private let posterImages: [ParallaxImage] = titles
.map { $0.lowercased().components(separatedBy: .whitespaces).joined() }
.map { movie in
- ["5", "4", "3", "2", "1"].map { return "\(movie)-\($0)" }
+ ["5"].map { return "\(movie)-\($0)" }
}
.compactMap {
$0.compactMap { UIImage(named: $0) }
However, it seems that now disk based urls cannot be used for images in the top shelf. The image is never rendered on screen:
Just implemented Re:Lax and it looks great. Thanks
I use a ParallaxContainer in my CollectionViewCell, just like in your example. Works great, except for one problem: how can I prevent a subview from "expanding" when the cell is focussed ?
Here's an example:
Here the red UIView has a constraint so that its leading lines up with the "APP STORE" label, and the trailing of the "8:AM", but when focused this is no longer the case.
Again, thanks for the great work. If you'd like to Testflight the app, let me know I'd be happy to add your email to the list.
Any chance you can add SPM support?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.