Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Bottom bar 実装 #3

Closed
3 of 6 tasks
tora-muscle opened this issue Feb 2, 2023 · 10 comments
Closed
3 of 6 tasks

✨ Bottom bar 実装 #3

tora-muscle opened this issue Feb 2, 2023 · 10 comments
Assignees
Labels
closed 完了 enhancement New feature or request

Comments

@tora-muscle
Copy link
Owner

tora-muscle commented Feb 2, 2023

🎫 関連課題

✨ 実現したいこと

  • 先週の振り返りアイコン

  • 今週のやることページ(week)アイコン

  • カレンダーアイコン

    • 選択時00DBB5
    • 通常時96A7AF

🚩 やらないこと

  • 内部ロジック(login処理など)の実装
  • ライトモードへの対応

🔀 達成条件

  • イメージ通りに画面実装

👀 備考

スクリーンショット 2023-02-02 10 08 43

@tora-muscle tora-muscle added the enhancement New feature or request label Feb 2, 2023
@tora-muscle tora-muscle self-assigned this Feb 2, 2023
@tora-muscle tora-muscle changed the title ✨ ボトムバー実装 ✨ Bottom bar 実装 Feb 4, 2023
@tora-muscle
Copy link
Owner Author

tora-muscle commented Feb 4, 2023

🎨 デザイン変更

変更点

  • custom.app.badge.checkmark.fillcustom.square.fill
  • calendarcustom.checkmark.circle.fill

スクリーンショット 2023-02-04 11 34 58

@tora-muscle tora-muscle mentioned this issue Feb 7, 2023
16 tasks
@tora-muscle
Copy link
Owner Author

🔧 要件追加

  • Plan Do -result画面からAct画面遷移時
    • Bottom barには戻るボタンのみ追加

@tora-muscle
Copy link
Owner Author

tora-muscle commented Feb 7, 2023

🗒 メモ : flutterのように個別のWidgetとしてBottom bar を切り出したい

SwiftUIでボトムバーを再利用するには、以下のように自分自身を表示するViewを構造体で作成して、他の画面で使用する。

struct BottomBar: View {
    var body: some View {
        // Bottom Bar Content Here
    }
}

別の画面では、次のようにBottomBarを使用することができる。

struct SomeView: View {
    var body: some View {
        VStack {
            // Some View Content Here
            BottomBar()
        }
    }
}

tora-muscle added a commit that referenced this issue Feb 7, 2023
- 構造体プロパティの関数として実装し、View実装時に都度引数 color を指定できる実装にした。後々の「プログレスサークルの色を動的に変更させる」で効果を発揮しそう!
@tora-muscle
Copy link
Owner Author

tora-muscle commented Feb 7, 2023

🗒 メモ : Font.systemの引数でどんなデザインになるか

  • size : 単純にサイズ
  • weight : 文字の太さ
  • design : 文字等間隔、丸文字など...

https://capibara1969.com/1981/
この記事がわかりやすかった🙌

@tora-muscle
Copy link
Owner Author

🗒 .renderingMode(.template)を定義した際、先に.frame()すると怒られる件について

.renderingMode(.template)はサイズが指定されていない画像に対して変更を加える。
よって、.renderingMode(.template)より先に.frame(width: 30.0)などを定義すると

Cannot infer contextual base in reference to member 'template'
Value of type 'some View' has no member 'renderingMode'

と怒られる

self.tabItems[index].view
                    .tabItem {
                        Image(systemName: self.tabItems[index].image)
                            .renderingMode(.template)
                            .foregroundColor(self.selectedIndex == index ? Color("UIColorGreen") : Color("UIColorGray"))
                            .padding(.bottom, 30.0)
                            .frame(width: 30.0)
                    }

@tora-muscle
Copy link
Owner Author

tora-muscle commented Feb 9, 2023

🗒 タブバーの色を変更する方法

  • 想定していた「条件分岐での色変更」の実装は難しく、.accentColor()で変更するしかなかった
  • タブバー自体の色変更はviewのプロトコルイニシャライザで指定するしかないようだ。。。
    • しかもしかも!UIcolorしか指定できないのはダサいし悲しすぎ!!
struct BottomBar: View {
    
    // ボトムバーの色を定義
    init() {
        UITabBar.appearance().backgroundColor = .darkGray
        UITabBar.appearance().unselectedItemTintColor = .gray
        }

参考文献 ▼
https://tech.amefure.com/swift-tabview
他にも「バッジ表示方法」など、詳しくまとまっているから今後助けてもらえそう!

⚠️ 追記 ⚠️

  • 色に関してはイニシャライザで任意の色を設定する方法があった!

@tora-muscle
Copy link
Owner Author

tora-muscle commented Feb 9, 2023

👀 備考

#3 (comment)

残件ありにつき、本課題はまだ進行中とする
なお、作業ブランチは #8 時に作成したブランチとする

@tora-muscle
Copy link
Owner Author

tora-muscle commented Feb 10, 2023

👀 残件

- [ ] figma更新

  • タブバーをセーフエリア内に収める

@tora-muscle
Copy link
Owner Author

tora-muscle commented Feb 11, 2023

🗒 カスタムタブバーの実装方法

  • Stackを使い分けることで任意の形のタブバーを実装することができた
  • アイコン選択と表示画面の連動部分の実装はモデルとしてアイコンに view を紐づけることで解決!

▼ モデル

struct BottomBarItem {
    let image: String
    let view: AnyView
}

▼ 中身

let bottomBarItems = [
        BottomBarItem(image: "graduationcap.fill", view: AnyView(ActView())),
        BottomBarItem(image: "square.fill", view: AnyView(PlanDoView())),
        BottomBarItem(image: "checkmark.circle.fill", view: AnyView(CheckView()))
    ]
タブバーの実装
//MARK: ボトムバーの実装
struct BottomBar: View {
    
    // タブの選択値と初期値.
    @State private var selected = 0
    
    var body: some View {
        
        ZStack {
            
            // 背景色.
            Color.backGroundColorGray.ignoresSafeArea()
            
            // メイン画面部分はTabViewで定義.
            TabView(selection: $selected) {
                ForEach(0 ..< 3) { index in
                    bottomBarItems[index].view
                        .tag(index)
                }
            }
            // PageTabスタイルを利用する(インジケータは非表示).
            .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
            
            VStack {
                
                Spacer(minLength: 0)
                
                // タブビュー部分.
                HStack {
                    ForEach(0 ..< 3) { index in
                        Image(systemName: bottomBarItems[index].image)
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: 20, height: 20)
                            .onTapGesture {
                                self.selected = index
                            }
                            .foregroundColor(self.selected == index ? Color.black : Color.gray)
                    }
                }
                .padding(.vertical, 10.0)
                .padding(.horizontal, 20.0)
                .background(Color.white.clipShape(Capsule()))
                .shadow(color: Color.black.opacity(0.3), radius: 5, x: -5, y: 5)
            }
        }
    }
}

▼ 参考記事

@tora-muscle
Copy link
Owner Author

tora-muscle commented Feb 11, 2023

👀 残件

  • デザイン部分の修正

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed 完了 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant