Skip to content

Commit

Permalink
feat: macos ci
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Dec 4, 2024
1 parent 0ddcf00 commit 900be84
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 34 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,49 @@ jobs:
- name: Build example for iOS
run: |
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
build-macos:
runs-on: macos-15
env:
TURBO_CACHE_DIR: .turbo/macos
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Build package
run: yarn build

- name: Install xcbeautify
run: |
brew install xcbeautify
- name: Cache turborepo for macOS
uses: actions/cache@v3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-macos-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-macos-
- name: Check turborepo cache for macOS
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:macos --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:macos').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi
- name: Install cocoapods
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
cd apps/example
pod install --project-directory=macos
env:
NO_FLIPPER: 1

- name: Build example for macOS
run: |
yarn turbo run build:macos --cache-dir="${{ env.TURBO_CACHE_DIR }}"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build:android": "turbo run build:android",
"build:android:fabric": "turbo run build:android:fabric",
"build:ios": "turbo run build:ios",
"build:macos": "turbo run build:macos",
"build:ios-expo": "turbo run build:ios-expo",
"build:android-expo": "turbo run build:android-expo",
"publish-packages": "turbo run build lint && changeset version && changeset publish"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#import <React/RCTUIManager.h>
#import <React/RCTImageLoader.h>
#import <React/RCTBridge.h>
#if TARGET_OS_OSX
#import <React/RCTUIKit.h>
#endif

#if TARGET_OS_OSX
#import <AppKit/AppKit.h>
Expand Down
60 changes: 30 additions & 30 deletions packages/react-native-bottom-tabs/ios/TabViewImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ struct TabViewImpl: View {
#else
@Weak var tabBar: UITabBar?
#endif

var onSelect: (_ key: String) -> Void
var onLongPress: (_ key: String) -> Void
var onLayout: (_ size: CGSize) -> Void
var onTabBarMeasured: (_ height: Int) -> Void

var body: some View {
TabView(selection: $props.selectedPage) {
ForEach(props.children.indices, id: \.self) { index in
Expand All @@ -34,7 +34,7 @@ struct TabViewImpl: View {
guard let key = props.items.filter({
!$0.hidden || $0.key == props.selectedPage
})[safe: index]?.key else { return }

if isLongPress {
onLongPress(key)
emitHapticFeedback(longPress: true)
Expand Down Expand Up @@ -73,17 +73,17 @@ struct TabViewImpl: View {
#endif
}
}

@ViewBuilder
private func renderTabItem(at index: Int) -> some View {
let tabData = props.items[safe: index]
let isHidden = tabData?.hidden ?? false
let isFocused = props.selectedPage == tabData?.key

if !isHidden || isFocused {
let child = props.children[safe: index] ?? PlatformView()
let icon = props.icons[index]

RepresentableView(view: child)
.ignoresTopSafeArea(
props.ignoresTopSafeArea,
Expand All @@ -103,7 +103,7 @@ struct TabViewImpl: View {
#if !os(macOS)
updateTabBarAppearance(props: props, tabBar: tabBar)
#endif

#if os(iOS)
guard index >= 4,
let key = tabData?.key,
Expand All @@ -113,13 +113,13 @@ struct TabViewImpl: View {
}
}
}

func emitHapticFeedback(longPress: Bool = false) {
#if os(iOS)
if !props.hapticFeedbackEnabled {
return
}

if longPress {
UINotificationFeedbackGenerator().notificationOccurred(.success)
} else {
Expand All @@ -132,12 +132,12 @@ struct TabViewImpl: View {
#if !os(macOS)
private func updateTabBarAppearance(props: TabViewProps, tabBar: UITabBar?) {
guard let tabBar else { return }

if props.scrollEdgeAppearance == "transparent" {
configureTransparentAppearance(tabBar: tabBar, props: props)
return
}

configureStandardAppearance(tabBar: tabBar, props: props)
}
#endif
Expand All @@ -149,8 +149,8 @@ private func createFontAttributes(
inactiveTintColor: PlatformColor?
) -> [NSAttributedString.Key: Any] {
var attributes: [NSAttributedString.Key: Any] = [:]


if family != nil || weight != nil {
attributes[.font] = RCTFont.update(
nil,
Expand All @@ -164,7 +164,7 @@ private func createFontAttributes(
} else {
attributes[.font] = UIFont.boldSystemFont(ofSize: size)
}

return attributes
}

Expand All @@ -180,25 +180,25 @@ private func configureTransparentAppearance(tabBar: UITabBar, props: TabViewProp
tabBar.barTintColor = props.barTintColor
tabBar.isTranslucent = props.translucent
tabBar.unselectedItemTintColor = props.inactiveTintColor

guard let items = tabBar.items else { return }

let fontSize = props.fontSize != nil ? CGFloat(props.fontSize!) : tabBarDefaultFontSize
let attributes = createFontAttributes(
size: fontSize,
family: props.fontFamily,
weight: props.fontWeight,
inactiveTintColor: nil
)

items.forEach { item in
item.setTitleTextAttributes(attributes, for: .normal)
}
}

private func configureStandardAppearance(tabBar: UITabBar, props: TabViewProps) {
let appearance = UITabBarAppearance()

// Configure background
switch props.scrollEdgeAppearance {
case "opaque":
Expand All @@ -207,33 +207,33 @@ private func configureStandardAppearance(tabBar: UITabBar, props: TabViewProps)
appearance.configureWithDefaultBackground()
}
appearance.backgroundColor = props.barTintColor

// Configure item appearance
let itemAppearance = UITabBarItemAppearance()
let fontSize = props.fontSize != nil ? CGFloat(props.fontSize!) : tabBarDefaultFontSize

var attributes = createFontAttributes(
size: fontSize,
family: props.fontFamily,
weight: props.fontWeight,
inactiveTintColor: props.inactiveTintColor
)

if let inactiveTintColor = props.inactiveTintColor {
attributes[.foregroundColor] = inactiveTintColor
}

if let inactiveTintColor = props.inactiveTintColor {
itemAppearance.normal.iconColor = inactiveTintColor
}

itemAppearance.normal.titleTextAttributes = attributes

// Apply item appearance to all layouts
appearance.stackedLayoutAppearance = itemAppearance
appearance.inlineLayoutAppearance = itemAppearance
appearance.compactInlineLayoutAppearance = itemAppearance

// Apply final appearance
tabBar.standardAppearance = appearance
if #available(iOS 15.0, *) {
Expand All @@ -259,7 +259,7 @@ extension View {
self
}
}

@ViewBuilder
func tabBadge(_ data: String?) -> some View {
if #available(iOS 15.0, macOS 15.0, visionOS 2.0, tvOS 15.0, *) {
Expand All @@ -276,7 +276,7 @@ extension View {
self
}
}

@ViewBuilder
func ignoresTopSafeArea(
_ flag: Bool,
Expand All @@ -290,7 +290,7 @@ extension View {
.ignoresSafeArea(.container, edges: .bottom)
}
}

#if !os(macOS)
@ViewBuilder
func configureAppearance(props: TabViewProps, tabBar: UITabBar?) -> some View {
Expand Down Expand Up @@ -321,7 +321,7 @@ extension View {
}
}
#endif

@ViewBuilder
func tintColor(_ color: PlatformColor?) -> some View {
if let color {
Expand All @@ -335,7 +335,7 @@ extension View {
self
}
}

// Allows TabView to use unfilled SFSymbols.
// By default they are always filled.
@ViewBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ Pod::Spec.new do |s|
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => "14.0", :visionos => "1.0", :tvos => "15.1", :macos => "11.0" }
s.ios.deployment_target = "14.0"
s.visionos.deployment_target = "1.0"
s.tvos.deployment_target = "15.1"
s.osx.deployment_target = "11.0"

s.source = { :git => "https://github.com/okwasniewski/react-native-bottom-tabs.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
Expand Down
15 changes: 15 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@
],
"outputs": []
},
"build:macos": {
"env": ["RCT_NEW_ARCH_ENABLED"],
"inputs": [
"packages/*/package.json",
"packages/*/*.podspec",
"packages/*/ios",
"packages/*/src/*.ts",
"packages/*/src/*.tsx",
"apps/example/package.json",
"apps/example/macos",
"!apps/example/macos/build",
"!apps/example/macos/Pods"
],
"outputs": []
},
"build:ios-expo": {
"env": ["RCT_NEW_ARCH_ENABLED"],
"inputs": [
Expand Down

0 comments on commit 900be84

Please sign in to comment.