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

세부 공지사항 UI 구현 #93

Merged
merged 4 commits into from
Mar 8, 2024
Merged

세부 공지사항 UI 구현 #93

merged 4 commits into from
Mar 8, 2024

Conversation

WhiteHyun
Copy link
Member

@WhiteHyun WhiteHyun commented Mar 8, 2024

Screenshots 📸

시연 영상(뒤로가기 색은 신경 안쓰셔도 됩니다)
Screen Recording 2024-03-08 at 6 25 49 PM



고민, 과정, 근거 💬

공지를 눌러서 공지 세부 사항으로 넘어가야 하는데 Disclosure를 어떻게 없앨까?

ZStack을 활용하여 NavigationLink를 만든 뒤 opacity를 0으로 설정해서 보이지 않도록 구현했습니다.

Figma에 나와있는 bullet-style을 어떻게 구현해야할까?

단순히 공지사항에 문자를 그대로 보여주기만 하면 되는 문제이긴 하나, bullet이 들어왔을 때 동그라미 형식으로 띄워줘야하는 문제가 있었습니다.
그리고 bullet-style 텍스트와 그 외 텍스트는 폰트가 다르므로, 구분해서 적용해야했습니다.

해결

텍스트가 처음에 -또는 *로 시작하는지 Regex를 통해 확인합니다.

// 공백이 없거나 계속 존재하는 경우 + `-` 또는 `*`가 있는 경우를 찾습니다.
if block.content.starts(with: /\s*[-*]/) {
  // ...
}

만약 찾으면 BulletTextView에게 text를 넘깁니다.

if block.content.starts(with: /\s*[-*]/) {
  BulletTextView(content: block.content)
}

디자인을 보면, 상위 불렛과, 그 외 하위 불렛으로 나뉘어 표현되기도 합니다. 따라서 -, *이전의 공백의 개수를 알아야할 필요가 있습니다.
그리고 Regex로 확인할 수 있습니다.[1]

struct BulletTextView: View {
  ...
  init(content: String) {
    guard let match = content.firstMatch(of: /(?<spacing>\s*)[-*]\s*?(?<content>[^\s].*)/)
    else {
      ...
    }
    ...

또한, 하위불렛과 상위불렛끼리 구분할 때 띄어쓰기가 일관되지 않을 것을 고려하여 공백 개수에서 2만큼 나누었습니다.
예를 들면, 공백이 2개이거나 3개라면 2로 나누어 전부 1로 맞추는 거예요!

struct BulletTextView: View {
  ...
  init(...) {
    ...
    // Calculates the spacing count by dividing the number of leading spaces by 2.
    // This adjustment ensures a consistent and visually appealing spacing, regardless of minor irregularities in the original spacing.
    let repeatSpaceCount = match.spacing.count / 2
    spacingCount = CGFloat(repeatSpaceCount)
  }
  var body: some View {
    HStack {
      Spacer()
        .frame(width: Metrics.bulletPrefixSpacingPerOne * CGFloat(spacingCount) + Metrics.bulletSpacingAlpha)
      Label(...)
      Spacer()
    }



References 📋

  1. Meet Swift Regex




- Implemented a NavigationLink for announcements, making them tappable. Used a `ZStack` to set the NavigationLink's opacity to 0 and display a custom-designed Label in the background
- Implemented the display of `bullet-style` markdown using `Label` View, with `circle.fill` as the system image for icons, creating a visually intuitive list representation.
- Added visual distinction for sub-bullet styles through calculated spacing from the leading edge, enhancing readability of nested items.
- Introduced a `TextBlock` struct to encapsulate text with a unique `UUID` id, addressing potential issues with duplicate content in `ForEach` loops.
- Created the `BuilletStyleView` to encapsulate the bullet-style presentation, simplifying the `NoticeDetailView`'s code structure.
@WhiteHyun WhiteHyun added ⚙️ Settings Settings View 🔨 Implementation New feature or request labels Mar 8, 2024
@WhiteHyun WhiteHyun added this to the v2.0.0 milestone Mar 8, 2024
@WhiteHyun WhiteHyun requested a review from a team March 8, 2024 09:15
@WhiteHyun WhiteHyun self-assigned this Mar 8, 2024
Copy link
Contributor

@eung7 eung7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다! 은근 복잡 하셨을 수도 있으실 것 같은데
너무 깔끔하게 잘 해주셨네요!! 🥹

@eung7 eung7 merged commit 5c07a36 into main Mar 8, 2024
2 checks passed
@eung7 eung7 deleted the feature/settings/92 branch March 8, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 Implementation New feature or request ⚙️ Settings Settings View
Projects
Development

Successfully merging this pull request may close these issues.

공지사항 리스트 아이템을 눌러 세부 공지사항을 확인한다.
2 participants