exyte / macaw-examples Goto Github PK
View Code? Open in Web Editor NEWVarious usages of the Macaw library
License: MIT License
Various usages of the Macaw library
License: MIT License
I'd like to add an image to the periodic table.
Is there any way?
The Podfile uses a fork. To compile the examples, I had to remove that path parameter from the Podfile.
I'm trying to change color of shape using following code:
@discardableResult public func replaceColors(node: Node, color: Fill?) -> Bool {
if let shape = node as? Shape {
shape.fill = color
return true
}
return false
}
At that moment, following code will be called:
group.contentsVar.onChange { [weak self] _ in
self?.updateRenderers()
}
private func updateRenderers() {
renderers.forEach { $0.dispose() }
renderers.removeAll()
if let updatedRenderers = group?.contents.compactMap ({ child -> NodeRenderer? in
guard let interval = renderingInterval else {
print("setNeedsDisplay=6-2")
return RenderUtils.createNodeRenderer(child, view: view, animationCache: animationCache)
}
let index = AnimationUtils.absoluteIndex(child, useCache: true)
if index > interval.from && index < interval.to {
print("setNeedsDisplay=6-3")
return RenderUtils.createNodeRenderer(child, view: view, animationCache: animationCache, interval: interval)
}
return .none
}) {
renderers = updatedRenderers
}
}
Btw when the color of shape is changed, updateRenderers() will be called much time.
It lowered the speed of the app.
How can we call updateRenderers() only once for changed shape?
class NodeRenderer {
weak var view: MView?
fileprivate let onNodeChange: () -> Void
fileprivate let disposables = GroupDisposable()
fileprivate var active = false
weak var animationCache: AnimationCache?
init(node: Node, view: MView?, animationCache: AnimationCache?) {
self.view = view
self.animationCache = animationCache
onNodeChange = { [unowned node, weak view] in
guard let isAnimating = animationCache?.isAnimating(node) else {
return
}
if isAnimating {
return
}
DispatchQueue.main.async {
print("setNeedsDisplay=6")
view?.setNeedsDisplay()
}
}
addObservers()
}
view?.setNeedsDisplay() needs to be wrapped with DispatchQueue.main.async {}.
If not, we have crash for iOS 13.
But after we wrap it, it is very slow when changing color of shape.
I found the reason.
When changing color of shape, this framework is doing rerendering for whole group using group rendering.
Now it needs to be called for main thread as you can see above.
But the speed is very slow because of calling main thread much time.
How can we fix this issue?
Please let me know if you have any thought.
Something similar like: http://dmitrybaranovskiy.github.io/raphael/easing.html
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.