From 81926f16257617240a5dcb2ad99cb18bda4bf877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwa=C5=9Bniewski?= Date: Wed, 30 Oct 2024 20:22:08 +0100 Subject: [PATCH] feat: allow for not filled sf symbols (#98) --- example/src/Examples/SFSymbols.tsx | 2 +- ios/TabViewImpl.swift | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/example/src/Examples/SFSymbols.tsx b/example/src/Examples/SFSymbols.tsx index 6e16601..827844f 100644 --- a/example/src/Examples/SFSymbols.tsx +++ b/example/src/Examples/SFSymbols.tsx @@ -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: '!', }, { diff --git a/ios/TabViewImpl.swift b/ios/TabViewImpl.swift index 21b3a9a..4eec7ef 100644 --- a/ios/TabViewImpl.swift +++ b/ios/TabViewImpl.swift @@ -75,6 +75,7 @@ struct TabViewImpl: View { .tag(tabData?.key) .tabBadge(tabData?.badge) } + } .onTabItemLongPress({ index in if let key = props.items[safe: index]?.key { @@ -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 ?? "") @@ -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 } @@ -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 + } + } }