Comments (3)
Hey @iAlirezaKML, mind sharing some more information about your implementation?
Do you use standalone components or do you have a controller-centric setup? And at what time do you set your delegate?
from spots.
Hi @zenangst, of course, here's an implementation:
import UIKit
import Spots
enum KBComponentKind: String, StringConvertible {
var string: String {
return rawValue
}
case contactView
}
class ContactView: UIView {
let titleLabel: UILabel = {
let label = UILabel.init()
label.textAlignment = .center
label.textColor = .gray
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(titleLabel)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
titleLabel.frame = frame
}
}
extension ContactView: ItemConfigurable {
func configure(with item: Item) {
titleLabel.text = item.title
}
func computeSize(for item: Item, containerSize: CGSize) -> CGSize {
return CGSize.init(width: containerSize.width,
height: 44)
}
}
class Delegator: NSObject {}
extension Delegator: ComponentDelegate {
func component(_ component: Component, itemSelected item: Item) {
print(#function) // not called!!!
print(component, item)
}
func component(_ component: Component, willDisplay view: ComponentView, item: Item) {
print(#function) // called!
if item.kind == KBComponentKind.contactView.rawValue {
view.transform = CGAffineTransform.init(scaleX: 0.01, y: 0.01)
view.alpha = 0
UIView.animate(withDuration: 0.8, delay: 0.1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.3, options: [.curveEaseOut], animations: {
view.alpha = 1
view.transform = CGAffineTransform.identity
}, completion: nil)
}
}
func component(_ component: Component, didEndDisplaying view: ComponentView, item: Item) {
print(#function) // called!
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow.init(frame: UIScreen.main.bounds)
self.window = window
Configuration.shared.register(view: ContactView.self, identifier: KBComponentKind.contactView)
Configuration.shared.registerDefault(view: ContactView.self)
let model = ComponentModel.init(
kind: .grid,
layout: Layout.init(span: 3,
dynamicSpan: false,
dynamicHeight: false,
itemsPerRow: 3,
itemSpacing: 1,
lineSpacing: 1,
inset: Inset.init(padding: 12),
showEmptyComponent: false,
infiniteScrolling: false),
items: [
Item(title: "Sindre Moen", kind: "contactView"),
Item(title: "Torgeir Øverland", kind: "contactView"),
Item(title: "Francesco Rodriguez", kind: "contactView"),
Item(title: "Henriette Røseth", kind: "contactView"),
Item(title: "Peter Sergeev", kind: "contactView"),
Item(title: "John Terje Sirevåg", kind: "contactView"),
Item(title: "Chang Xiangzhong", kind: "contactView")
]
)
let component = Component.init(model: model)
let controller = SpotsController.init(components: [component])
let delegator = Delegator.init()
controller.delegate = delegator
window.rootViewController
window.makeKeyAndVisible()
return true
}
}
from spots.
I've got the problem, since in my implementation there is no strong references hold for delegator
object, and spots just holds a weak reference to the component delegate, after components are being created, the delegator
is not being referenced by any strong variable and it's being pulled out of memory.
Fixed it by holding an strong reference in AppDelegate
.
P.S.: Please update the documentation, there are a ton of changes made and has not been reflected to the docs. By the way live editing doesn't work and gets compile errors.
Another question: how can I access to the selected view inside of component(_ component: Component, itemSelected item: Item)
to animate on selection?
from spots.
Related Issues (20)
- Add a test for checking the new `clean` property in `prepareItems`. HOT 1
- Method does not override any method from its superclass
- Improve naming of `itemsPerRow` HOT 12
- Update Example apps HOT 8
- CryptoSwift requirement 0.6.0 does not work with Xcode 9. HOT 4
- Building Scheme Spots-tvOS exit error 65 HOT 6
- no ad was available Apple TV os HOT 4
- Cant Play add HOT 1
- Item with uilabel not expanding with text after sizeToFit HOT 14
- Event handling HOT 3
- Enable linting HOT 1
- func configure(_ item: inout Item) change. HOT 5
- please add more visual example projects just like the cover image implied HOT 1
- Feature Request: Migration from HUB to Spots?
- compile error with Xcode 9.3
- weird problem on pop. HOT 1
- Documentation
- Child components
- Crash on iOS 13 Beta 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spots.