Skip to content

Commit

Permalink
fix: properly set icon aspect ratio (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski authored Oct 21, 2024
1 parent 10a35c9 commit 97c7aed
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions ios/TabViewProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ struct TabData: Codable {
private var eventDispatcher: RCTEventDispatcherProtocol?
private var imageLoader: RCTImageLoaderProtocol?
private var iconSize = CGSize(width: 27, height: 27)

@objc var onPageSelected: RCTDirectEventBlock?

@objc var icons: NSArray? {
didSet {
loadIcons(icons)
}
}

@objc var sidebarAdaptable: Bool = false {
didSet {
props.sidebarAdaptable = sidebarAdaptable
}
}

@objc var disablePageAnimations: Bool = false {
didSet {
props.disablePageAnimations = disablePageAnimations
Expand All @@ -46,31 +46,31 @@ struct TabData: Codable {
props.labeled = labeled
}
}

@objc var ignoresTopSafeArea: Bool = false {
didSet {
props.ignoresTopSafeArea = ignoresTopSafeArea
}
}

@objc var selectedPage: NSString? {
didSet {
props.selectedPage = selectedPage as? String
}
}

@objc var scrollEdgeAppearance: NSString? {
didSet {
props.scrollEdgeAppearance = scrollEdgeAppearance as? String
}
}

@objc var translucent: Bool = true {
didSet {
props.translucent = translucent
}
}

@objc var items: NSArray? {
didSet {
props.items = parseTabData(from: items)
Expand All @@ -82,23 +82,23 @@ struct TabData: Codable {
props.barTintColor = RCTConvert.uiColor(barTintColor)
}
}

@objc public convenience init(eventDispatcher: RCTEventDispatcherProtocol, imageLoader: RCTImageLoader) {
self.init()
self.eventDispatcher = eventDispatcher
self.imageLoader = imageLoader
}

public override func didUpdateReactSubviews() {
props.children = reactSubviews()
}

public override func layoutSubviews() {
super.layoutSubviews()
setupView()
props.children = reactSubviews()
}

private func setupView() {
if self.hostingController != nil {
return
Expand All @@ -116,7 +116,7 @@ struct TabData: Codable {
hostingController.didMove(toParent: parentViewController)
}
}

private func loadIcons(_ icons: NSArray?) {
// TODO: Diff the arrays and update only changed items.
// Now if the user passes `unfocusedIcon` we update every item.
Expand All @@ -127,8 +127,8 @@ struct TabData: Codable {
with: imageSource.request,
size: imageSource.size,
scale: imageSource.scale,
clipped: true,
resizeMode: RCTResizeMode.contain,
clipped: false,
resizeMode: RCTResizeMode.cover,
progressBlock: { _,_ in },
partialLoad: { _ in },
completionBlock: { error, image in
Expand All @@ -144,11 +144,11 @@ struct TabData: Codable {
}
}
}

private func parseTabData(from array: NSArray?) -> TabData? {
guard let array else { return nil }
var items: [TabInfo] = []

for value in array {
if let itemDict = value as? [String: Any] {
items.append(
Expand All @@ -161,7 +161,7 @@ struct TabData: Codable {
)
}
}

return TabData(tabs: items)
}
}
Expand Down

0 comments on commit 97c7aed

Please sign in to comment.