Giter Site home page Giter Site logo

Won't display in TabView about faswiftui HOT 15 OPEN

 avatar commented on July 18, 2024
Won't display in TabView

from faswiftui.

Comments (15)

mattmaddux avatar mattmaddux commented on July 18, 2024 1

My goal has always been to also include an option for a view that SwiftUI sees as an image rather than text, and I think that would fit the bill for tab items. I’m trying to figure out if that is possible.

from faswiftui.

mattmaddux avatar mattmaddux commented on July 18, 2024

It should work fine in a tab view. Have you confirmed it’s working in other views? It sounds like the font files haven’t been added to the target, or you’ve got a typo in the icon name.

Double check step 4 from the read me.

from faswiftui.

 avatar commented on July 18, 2024

@mattmaddux Ok ... In the Target Membership section, the only thing available there should be my app name right?

from faswiftui.

 avatar commented on July 18, 2024

@mattmaddux It works fine everywhere else I use them. Just not in TabView.

from faswiftui.

mattmaddux avatar mattmaddux commented on July 18, 2024

Hmm, okay, if it’s working elsewhere then you’ve got it installed correctly. Might be a bug, or might be an oddity in Tab View. Would you mind posting your tab view code and I’ll play with it myself?

from faswiftui.

 avatar commented on July 18, 2024

@mattmaddux
TabView { Text("First Page") .tabItem{ Image(systemName: "square.fill") .font(.system(size: 21)) } .tag(0) Text("Second Page") .tabItem{ Image(systemName: "triangle.fill") .font(.system(size: 21)) } .tag(1) Text("Third Page") .tabItem{ Image(systemName: "hexagon.fill") .font(.system(size: 21)) } .tag(2) Text("Fourth Page") .tabItem{ Image(systemName: "triangle.fill") .font(.system(size: 21)) } .tag(3) Text("Fifth Page") .tabItem{ Image(systemName: "square.fill") .font(.system(size: 21)) } .tag(4) } .accentColor(Color(.label))

from faswiftui.

mattmaddux avatar mattmaddux commented on July 18, 2024

So the code you posted isn't using FASwiftUI at all. With Image(systemName: "square.fill") you're calling SF Symbols, and "square.fill" isn't a valid glyph.
(Correction: it IS a valid glyph!)

To call FASwiftUI, call FAText(iconName: "square", size: 21).

HOWEVER, you're right that it isn't showing up correctly in the tab view itself. Like if I try the following:

TabView {
    FAText(iconName: "square", size: 21)
        .tabItem{ FAText(iconName: "square", size: 21) }
        .tag(0)
    FAText(iconName: "triangle", size: 21)
        .tabItem{ FAText(iconName: "triangle", size: 21) }
        .tag(1)
    FAText(iconName: "hexagon", size: 21)
        .tabItem{ FAText(iconName: "hexagon", size: 21) }
        .tag(2)
    FAText(iconName: "square", size: 21)
        .tabItem{ FAText(iconName: "square", size: 21) }
        .tag(3)
    FAText(iconName: "triangle", size: 21)
        .tabItem{ FAText(iconName: "triangle", size: 21) }
        .tag(4)
}

The icons show correctly when they are the main view, but not in the tab bar, like you said.

So there's definitely something weird and I'll look into it.

from faswiftui.

 avatar commented on July 18, 2024

Yeah, I know I’m using SF symbols. It’s the only icons that work in the TabView. Let me know if you figure out something.

from faswiftui.

wutzi15 avatar wutzi15 commented on July 18, 2024

I can confirm this. I have the following code:

import SwiftUI
import FASwiftUI

struct ContentView: View {
    var body: some View {
        TabView {
            Text("First View")
                .tabItem {
                    Image(systemName: "house.fill")
                    Text("First")
            }.tag(0)
            Text("Second View")
                .tabItem {
                    Image(systemName: "flame.fill")
                    Text("Second")
            }.tag(1)
            FAText(iconName: "bomb", size: 21)
                .tabItem {
                    FAText(iconName: "bomb", size: 21)
                    Text("Third")
            }.tag(2)
            Text("Fourth View")
                .tabItem {
                    Image(systemName: "line.horizontal.3")
                    Text("4th")
            }.tag(3)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Which generated this view:
Bildschirmfoto 2020-03-14 um 21 54 03
Any Ideas on how to fix this?

from faswiftui.

mattmaddux avatar mattmaddux commented on July 18, 2024

So far I haven't been able to figure out a solution. It seems like tab items are a little picky about what they allow. The documentation for TabView says:

Tab views only support tab items of type Text, Image, or an image followed by text. Passing any other type of view results in a visible but empty tab item.

FAText views ARE text according to SwiftUI. But it seems like it doesn't quite fit the structure the tab item view is expecting.

I'll keep experimenting.

from faswiftui.

wutzi15 avatar wutzi15 commented on July 18, 2024

What a pity.
Keep up the good work ;)

from faswiftui.

mickeyl avatar mickeyl commented on July 18, 2024

It‘s been almost two years now… got anything further with that issue? Happy new year, btw.

from faswiftui.

mattmaddux avatar mattmaddux commented on July 18, 2024

@mickeyl Unfortunately my work has brought me away from SwiftUI in that time, so I haven't been able to commit time to solving this. However, there have been a number of forks that have made some additions. It might be worthwhile to browse those and see what changes have been made. I will try to make time for that soon.

from faswiftui.

nxnam avatar nxnam commented on July 18, 2024

@mattmaddux Is there any update to fix this issue?

from faswiftui.

martyuiop avatar martyuiop commented on July 18, 2024

Workaround for this (i'll look at correcting in FASwift project)
in your Views init include the following. As an e.g. obviously change the font name etc. to suit your specific case.
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont.init(name: "FontAwesome5Pro-Solid", size: 20)! ], for: .normal)
Then actually call a text item for your tabitem eg.
.tabItem { Text(" barcode-read") }
This does obviously change ALL tab item text for that view to use the fontawesome otf though

from faswiftui.

Related Issues (19)

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.