@@ -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,
@@ -171,36 +174,100 @@ struct TabItem: View {
171174}
172175
173176private func updateTabBarAppearance( props: TabViewProps , tabBar: UITabBar ? ) {
174- guard let tabBar else { return }
175- let appearanceType = props. scrollEdgeAppearance
176-
177- if ( appearanceType == " transparent " ) {
178- tabBar. barTintColor = props. barTintColor
179- tabBar. isTranslucent = props. translucent
180- tabBar. unselectedItemTintColor = props. inactiveTintColor
181- return
177+ guard let tabBar else { return }
178+
179+ if props. scrollEdgeAppearance == " transparent " {
180+ configureTransparentAppearance ( tabBar: tabBar, props: props)
181+ return
182+ }
183+
184+ configureStandardAppearance ( tabBar: tabBar, props: props)
185+ }
186+
187+ private func createFontAttributes(
188+ size: CGFloat ,
189+ family: String ? ,
190+ weight: String ? ,
191+ inactiveTintColor: UIColor ?
192+ ) -> [ NSAttributedString . Key : Any ] {
193+ var attributes : [ NSAttributedString . Key : Any ] = [ : ]
194+
195+ if let inactiveTintColor {
196+ attributes [ . foregroundColor] = inactiveTintColor
197+ }
198+
199+ if family != nil || weight != nil {
200+ attributes [ . font] = RCTFont . update (
201+ nil ,
202+ withFamily: family,
203+ size: NSNumber ( value: size) ,
204+ weight: weight,
205+ style: nil ,
206+ variant: nil ,
207+ scaleMultiplier: 1.0
208+ )
209+ } else {
210+ attributes [ . font] = UIFont . boldSystemFont ( ofSize: size)
211+ }
212+
213+ return attributes
214+ }
215+
216+ private func configureTransparentAppearance( tabBar: UITabBar , props: TabViewProps ) {
217+ tabBar. barTintColor = props. barTintColor
218+ tabBar. isTranslucent = props. translucent
219+ tabBar. unselectedItemTintColor = props. inactiveTintColor
220+
221+ guard let items = tabBar. items else { return }
222+
223+ let fontSize = props. fontSize != nil ? CGFloat ( props. fontSize!) : UIFont . smallSystemFontSize
224+ let attributes = createFontAttributes (
225+ size: fontSize,
226+ family: props. fontFamily,
227+ weight: props. fontWeight,
228+ inactiveTintColor: props. inactiveTintColor
229+ )
230+
231+ items. forEach { item in
232+ item. setTitleTextAttributes ( attributes, for: . normal)
182233 }
234+ }
183235
236+ private func configureStandardAppearance( tabBar: UITabBar , props: TabViewProps ) {
184237 let appearance = UITabBarAppearance ( )
185-
186- switch appearanceType {
238+
239+ // Configure background
240+ switch props. scrollEdgeAppearance {
187241 case " opaque " :
188242 appearance. configureWithOpaqueBackground ( )
189243 default :
190244 appearance. configureWithDefaultBackground ( )
191245 }
192246 appearance. backgroundColor = props. barTintColor
193247
248+ // Configure item appearance
249+ let itemAppearance = UITabBarItemAppearance ( )
250+ let fontSize = props. fontSize != nil ? CGFloat ( props. fontSize!) : UIFont . smallSystemFontSize
251+
252+ let attributes = createFontAttributes (
253+ size: fontSize,
254+ family: props. fontFamily,
255+ weight: props. fontWeight,
256+ inactiveTintColor: props. inactiveTintColor
257+ )
258+
194259 if let inactiveTintColor = props. inactiveTintColor {
195- let itemAppearance = UITabBarItemAppearance ( )
196260 itemAppearance. normal. iconColor = inactiveTintColor
197- itemAppearance. normal. titleTextAttributes = [ . foregroundColor: inactiveTintColor]
198-
199- appearance. stackedLayoutAppearance = itemAppearance
200- appearance. inlineLayoutAppearance = itemAppearance
201- appearance. compactInlineLayoutAppearance = itemAppearance
202261 }
203262
263+ itemAppearance. normal. titleTextAttributes = attributes
264+
265+ // Apply item appearance to all layouts
266+ appearance. stackedLayoutAppearance = itemAppearance
267+ appearance. inlineLayoutAppearance = itemAppearance
268+ appearance. compactInlineLayoutAppearance = itemAppearance
269+
270+ // Apply final appearance
204271 tabBar. standardAppearance = appearance
205272 if #available( iOS 15 . 0 , * ) {
206273 tabBar. scrollEdgeAppearance = appearance. copy ( )
@@ -277,6 +344,15 @@ extension View {
277344 . onChange ( of: props. selectedActiveTintColor) { newValue in
278345 updateTabBarAppearance ( props: props, tabBar: tabBar)
279346 }
347+ . onChange ( of: props. fontSize) { newValue in
348+ updateTabBarAppearance ( props: props, tabBar: tabBar)
349+ }
350+ . onChange ( of: props. fontFamily) { newValue in
351+ updateTabBarAppearance ( props: props, tabBar: tabBar)
352+ }
353+ . onChange ( of: props. fontWeight) { newValue in
354+ updateTabBarAppearance ( props: props, tabBar: tabBar)
355+ }
280356 }
281357
282358 @ViewBuilder
0 commit comments