Comments (6)
Hi @CodeTropolis,
You're right that onTap
was renamed to onTapGesture
and documentation doesn't reflect it. So we'll update it.
But your examples are correct. Could you attach an SVG you're using? Probably a node you're trying to get is missing or it's an element which couldn't be tapped (for example, shape with stroke and without fill).
from svgview.
Here's the SVG(Github attachment not working): https://pastebin.com/Eguxingd
The SVG is a world map.
Not concerned about CSS id or class properties except for the necessary props required for tap recognition on a region.
Appreciate your help.
from svgview.
I reproduced your issue. Tap works on some parts of "americas" for me, but "europe" and "asia" can't be tapped at all. Will take a look.
from svgview.
I'm experiencing something similar.
I'm able to log to console upon a tap on both americas and europe but not asia. Also, the fill does not change color.
struct ZoneSelect: View {
var body: some View {
let filePath = Bundle.main.url(forResource: "zones.svg", withExtension: nil)!
let root = SVGView(contentsOf: filePath)
let zones = ["americas", "europe", "asia"]
zones.forEach { region in
let zone = root.svg?.getNode(byId: region)
zone?.onTapGesture {
print("Region: \(region) tapped!")
(zone as? SVGPath)?.fill = SVGColor.by(name: "orange")
}
}
return ScrollView(.horizontal) {
root.frame(width: 1280, height: 640)
}
}
}
from svgview.
That's because zone is not a path, it's a group containing several paths. You need to use something like this to change fill color:
func setColor(_ node: SVGNode, color: SVGColor) {
if let group = node as? SVGGroup {
for content in group.contents {
setColor(content, color: color)
}
} else if let shape = node as? SVGShape {
shape.fill = color
}
}
...
setColor(zone, color: SVGColor.by(name: "orange"))
from svgview.
Thank you Yuri! Appreciate your help.
from svgview.
Related Issues (20)
- stroke and fill with SVGNode HOT 1
- Carthage build failed: Task failed with exit code 75
- transform with CGAffineTransform scale, or rotation also moves the position of the node HOT 2
- Masking HOT 1
- Could you please create a new release tag (1.0.5)? HOT 1
- Animating color gradient changes
- Support for Filling SVG Paths with Patterns
- Animatable SVG Support?
- .help(_:) modifier does not work with SVGView
- Font weight support
- View updates changes HOT 1
- Change text
- Bugs in complex-effects sample code
- DOMParser working on Main thread
- Bugs when circle and rect need rotate
- Question: How to apply tint to SVGView? HOT 2
- Code samples do not work in Xcode 15 HOT 1
- SVGView(contentsOf: url) asynchronous question HOT 1
- Setting specific frame glitches with onTapGesture
- Question: Is it possible to get an array of the paths from the svg?
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 svgview.