Coder Social home page Coder Social logo

Comments (6)

ystrot avatar ystrot commented on August 23, 2024

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.

CodeTropolis avatar CodeTropolis commented on August 23, 2024

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.

ystrot avatar ystrot commented on August 23, 2024

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.

CodeTropolis avatar CodeTropolis commented on August 23, 2024

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.

ystrot avatar ystrot commented on August 23, 2024

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.

CodeTropolis avatar CodeTropolis commented on August 23, 2024

Thank you Yuri! Appreciate your help.

from svgview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.