Skip to content

Commit

Permalink
feat: allow for not filled sf symbols (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski authored Oct 30, 2024
1 parent 6dc2f3e commit 81926f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/src/Examples/SFSymbols.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function SFSymbols() {
: { sfSymbol: 'document.fill' },
unfocusedIcon: isAndroid
? require('../../assets/icons/chat_dark.png')
: { sfSymbol: 'bubble.left.fill' },
: { sfSymbol: 'document' },
badge: '!',
},
{
Expand Down
20 changes: 17 additions & 3 deletions ios/TabViewImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct TabViewImpl: View {
.tag(tabData?.key)
.tabBadge(tabData?.badge)
}

}
.onTabItemLongPress({ index in
if let key = props.items[safe: index]?.key {
Expand Down Expand Up @@ -163,6 +164,7 @@ struct TabItem: View {
Image(uiImage: icon)
} else if let sfSymbol, !sfSymbol.isEmpty {
Image(systemName: sfSymbol)
.noneSymbolVariant()
}
if (labeled != false) {
Text(title ?? "")
Expand Down Expand Up @@ -190,11 +192,11 @@ extension View {
func tabBadge(_ data: String?) -> some View {
if #available(iOS 15.0, macOS 15.0, visionOS 2.0, tvOS 15.0, *) {
if let data = data, !data.isEmpty {
#if !os(tvOS)
#if !os(tvOS)
self.badge(data)
#else
#else
self
#endif
#endif
} else {
self
}
Expand Down Expand Up @@ -256,4 +258,16 @@ extension View {
self
}
}

// Allows TabView to use unfilled SFSymbols.
// By default they are always filled.
@ViewBuilder
func noneSymbolVariant() -> some View {
if #available(iOS 15.0, *) {
self
.environment(\.symbolVariants, .none)
} else {
self
}
}
}

0 comments on commit 81926f1

Please sign in to comment.