@@ -22,6 +22,9 @@ class TabViewProps: ObservableObject {
2222 @Published var ignoresTopSafeArea : Bool = true
2323 @Published var disablePageAnimations : Bool = false
2424 @Published var hapticFeedbackEnabled : Bool = true
25+ @Published var fontSize : Int ?
26+ @Published var fontFamily : String ?
27+ @Published var fontWeight : String ?
2528
2629 var selectedActiveTintColor : UIColor ? {
2730 if let selectedPage = selectedPage,
@@ -166,36 +169,100 @@ struct TabItem: View {
166169}
167170
168171private func updateTabBarAppearance( props: TabViewProps , tabBar: UITabBar ? ) {
169- guard let tabBar else { return }
170- let appearanceType = props. scrollEdgeAppearance
172+ guard let tabBar else { return }
173+
174+ if props. scrollEdgeAppearance == " transparent " {
175+ configureTransparentAppearance ( tabBar: tabBar, props: props)
176+ return
177+ }
178+
179+ configureStandardAppearance ( tabBar: tabBar, props: props)
180+ }
181+
182+ private func createFontAttributes(
183+ size: CGFloat ,
184+ family: String ? ,
185+ weight: String ? ,
186+ inactiveTintColor: UIColor ?
187+ ) -> [ NSAttributedString . Key : Any ] {
188+ var attributes : [ NSAttributedString . Key : Any ] = [ : ]
189+
190+ if let inactiveTintColor {
191+ attributes [ . foregroundColor] = inactiveTintColor
192+ }
193+
194+ if family != nil || weight != nil {
195+ attributes [ . font] = RCTFont . update (
196+ nil ,
197+ withFamily: family,
198+ size: NSNumber ( value: size) ,
199+ weight: weight,
200+ style: nil ,
201+ variant: nil ,
202+ scaleMultiplier: 1.0
203+ )
204+ } else {
205+ attributes [ . font] = UIFont . boldSystemFont ( ofSize: size)
206+ }
207+
208+ return attributes
209+ }
171210
172- if ( appearanceType == " transparent " ) {
173- tabBar. barTintColor = props. barTintColor
174- tabBar. isTranslucent = props. translucent
175- tabBar. unselectedItemTintColor = props. inactiveTintColor
176- return
211+ private func configureTransparentAppearance( tabBar: UITabBar , props: TabViewProps ) {
212+ tabBar. barTintColor = props. barTintColor
213+ tabBar. isTranslucent = props. translucent
214+ tabBar. unselectedItemTintColor = props. inactiveTintColor
215+
216+ guard let items = tabBar. items else { return }
217+
218+ let fontSize = props. fontSize ?? 14
219+ let attributes = createFontAttributes (
220+ size: CGFloat ( fontSize) ,
221+ family: props. fontFamily,
222+ weight: props. fontWeight,
223+ inactiveTintColor: props. inactiveTintColor
224+ )
225+
226+ items. forEach { item in
227+ item. setTitleTextAttributes ( attributes, for: . normal)
177228 }
229+ }
178230
231+ private func configureStandardAppearance( tabBar: UITabBar , props: TabViewProps ) {
179232 let appearance = UITabBarAppearance ( )
180233
181- switch appearanceType {
234+ // Configure background
235+ switch props. scrollEdgeAppearance {
182236 case " opaque " :
183237 appearance. configureWithOpaqueBackground ( )
184238 default :
185239 appearance. configureWithDefaultBackground ( )
186240 }
187241 appearance. backgroundColor = props. barTintColor
188-
242+
243+ // Configure item appearance
244+ let itemAppearance = UITabBarItemAppearance ( )
245+ let fontSize = props. fontSize != nil ? CGFloat ( props. fontSize!) : UIFont . smallSystemFontSize
246+
247+ let attributes = createFontAttributes (
248+ size: fontSize,
249+ family: props. fontFamily,
250+ weight: props. fontWeight,
251+ inactiveTintColor: props. inactiveTintColor
252+ )
253+
189254 if let inactiveTintColor = props. inactiveTintColor {
190- let itemAppearance = UITabBarItemAppearance ( )
191255 itemAppearance. normal. iconColor = inactiveTintColor
192- itemAppearance. normal. titleTextAttributes = [ . foregroundColor: inactiveTintColor]
193-
194- appearance. stackedLayoutAppearance = itemAppearance
195- appearance. inlineLayoutAppearance = itemAppearance
196- appearance. compactInlineLayoutAppearance = itemAppearance
197256 }
198-
257+
258+ itemAppearance. normal. titleTextAttributes = attributes
259+
260+ // Apply item appearance to all layouts
261+ appearance. stackedLayoutAppearance = itemAppearance
262+ appearance. inlineLayoutAppearance = itemAppearance
263+ appearance. compactInlineLayoutAppearance = itemAppearance
264+
265+ // Apply final appearance
199266 tabBar. standardAppearance = appearance
200267 if #available( iOS 15 . 0 , * ) {
201268 tabBar. scrollEdgeAppearance = appearance. copy ( )
@@ -272,6 +339,15 @@ extension View {
272339 . onChange ( of: props. selectedActiveTintColor) { newValue in
273340 updateTabBarAppearance ( props: props, tabBar: tabBar)
274341 }
342+ . onChange ( of: props. fontSize) { newValue in
343+ updateTabBarAppearance ( props: props, tabBar: tabBar)
344+ }
345+ . onChange ( of: props. fontFamily) { newValue in
346+ updateTabBarAppearance ( props: props, tabBar: tabBar)
347+ }
348+ . onChange ( of: props. fontWeight) { newValue in
349+ updateTabBarAppearance ( props: props, tabBar: tabBar)
350+ }
275351 }
276352
277353 @ViewBuilder
0 commit comments