[ThirdParty] SwiftUI-Shimmer 해석하기

2025. 7. 27. 15:32·iOS/SwiftUI
반응형

👋 들어가기 전

로딩을 위해, 인디케이터를 돌릴 수도 있지만, 보여질 컨텐츠의 형태를 많이 보여주는

Shimmer Effect가 최근에 많이 보이는 것 같다.

 

이번에는 SwiftUI에서 SwiftUI-Shimmer 라이브러리를 해석해보고, 

 

사용되는 개념 중, 모르는 것들을 따로 정리해보자.


🏁 학습할 내용

      • 생소한 개념들
        • @Environment(\.layoutDirection)
        • BlendMode
        • RedactionReasons
      • 프로퍼티 분석

❓ 생소한 개념

@Environment(\.layoutDirection)

컨텐츠가 그려질 방향 (LTR, RTL) 

 

자세한 링크: https://hamp.tistory.com/244

 

BlendMode

두 뷰가 겹칠 때 어떻게 처리될 것인가??

 

자세한 링크: https://hamp.tistory.com/245

RedactionReasons

데이터를 가리는 이유를 열려줘

 

자세한 링크: https://hamp.tistory.com/246


📌 프로퍼티 분석

    public enum Mode { /// Gradient를 어떻게 활용할지 
        case mask /// 컨텐츠 마스킹
        case overlay(blendMode: BlendMode = .sourceAtop) /// 겹치기 
        case background /// 뒤에 배치
    } 

    private let animation: Animation // 적용할 애니메이션 
    private let gradient: Gradient // 적용할 Gradient 
    private let min, max: CGFloat // 영역의 최소 최대 범위
    private let mode: Mode // 위에 선어난 모드 
    @State private var isInitialState = true
    @Environment(\.layoutDirection) private var layoutDirection // 컨텐츠 표시 방햐아 (LTR or RTL)

    var startPoint: UnitPoint {
        if layoutDirection == .rightToLeft { // RTL
            isInitialState ? UnitPoint(x: max, y: min) : UnitPoint(x: 0, y: 1)
        } else { // LTR 
            isInitialState ? UnitPoint(x: min, y: min) : UnitPoint(x: 1, y: 1)
        }
    }

    /// The end unit point of our gradient, adjusting for layout direction.
    var endPoint: UnitPoint {
        if layoutDirection == .rightToLeft { // RTL
            isInitialState ? UnitPoint(x: 1, y: 0) : UnitPoint(x: min, y: max)
        } else { // LTR
            isInitialState ? UnitPoint(x: 0, y: 0) : UnitPoint(x: max, y: max)
        }
    }
    
        /*
     Calculating the gradient's animated start and end unit points:
     min,min
        \
         ┌───────┐         ┌───────┐
         │0,0    │ Animate │       │  "forward" gradient
     LTR │       │ ───────►│    1,1│  / // /
         └───────┘         └───────┘
                                    \
                                  max,max
                max,min
                  /
         ┌───────┐         ┌───────┐
         │    1,0│ Animate │       │  "backward" gradient
     RTL │       │ ───────►│0,1    │  \ \\ \
         └───────┘         └───────┘
                          /
                       min,max
     */

🏎️ startPoint와 endPoint

다른 부분은 이해가 됐지만 point 쪽을 조금 더 살펴보자.

LTR 기준으로 해석한다.

지금 보면 왼쪽위에서 -> 오른쪽아래로 검은색이 흘러간다.

그림으로 살펴보자.

먼저 startPoint와 endPoint는 이렇게 위치한다.

 

여기서 하얀 색 사각의 너비(높이)가 bandSize가 된다.

  • min = 0 - bandSize
  • max = 1 + bandSize

이후 이동 경로는 다음과 같다.

startPoint는 (min, min) 왼쪽 바깥에서, (1, 1) 오른쪽 아래 끝에 이동한다.

endPoint는 (0, 0) 왼쪽 위 끝에서, (max, max) 오른쪽 바깥으로 이동한다.


출처

https://github.com/markiv/SwiftUI-Shimmer

 

GitHub - markiv/SwiftUI-Shimmer: Shimmer is a super-light modifier that adds a shimmering effect to any SwiftUI View, for exampl

Shimmer is a super-light modifier that adds a shimmering effect to any SwiftUI View, for example, to show that an operation is in progress. It works well on light and dark modes, and across iOS, ma...

github.com

 

반응형

'iOS > SwiftUI' 카테고리의 다른 글

스크롤 할 떄, keyboard 자연스럽게 내리기  (2) 2025.08.15
TextEditor에 placeHolder 보여주기  (3) 2025.08.14
RedactionReasons  (1) 2025.07.27
BlendMode  (0) 2025.07.26
[@Environment] layoutDirection  (0) 2025.07.26
'iOS/SwiftUI' 카테고리의 다른 글
  • 스크롤 할 떄, keyboard 자연스럽게 내리기
  • TextEditor에 placeHolder 보여주기
  • RedactionReasons
  • BlendMode
Hamp
Hamp
남들에게 보여주기 부끄러운 잡다한 글을 적어 나가는 자칭 기술 블로그입니다.
  • Hamp
    Hamp의 분리수거함
    Hamp
  • 전체
    오늘
    어제
    • 분류 전체보기 (309) N
      • CS (30)
        • 객체지향 (2)
        • Network (7)
        • OS (6)
        • 자료구조 (1)
        • LiveStreaming (3)
        • 이미지 (1)
        • 잡다한 질문 정리 (0)
        • Hardware (2)
        • 이론 (6)
        • 컴퓨터 그래픽스 (0)
      • Firebase (3)
      • Programing Langauge (38)
        • swift (32)
        • python (5)
        • Kotlin (1)
      • iOS (132)
        • UIKit (37)
        • Combine (1)
        • SwiftUI (32)
        • Framework (7)
        • Swift Concurrency (22)
        • Tuist (6)
        • Setting (11)
        • Modularization (1)
        • Instruments (6)
      • PS (59)
        • 프로그래머스 (24)
        • 백준 (13)
        • LeetCode (19)
        • 알고리즘 (3)
      • Git (18)
        • 명령어 (4)
        • 이론 (2)
        • hooks (1)
        • config (2)
        • action (7)
      • Shell Script (2)
      • Linux (6)
        • 명령어 (5)
      • Spring (15) N
        • 어노테이션 (3) N
        • 튜토리얼 (11)
      • CI-CD (4)
      • Android (0)
        • Jetpack Compose (0)
      • AI (2) N
        • 이론 (2) N
  • 블로그 메뉴

    • 홈
    • 태그
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    dispatch
    IOS
    프로그래머스
    concurrency
    AVFoundation
    투포인터
    SwiftUI
    CS
    백준
    Swift
    GIT
    dfs
    Spring
    dp
    lifecycle
    boostcamp
    Tuist
    protocol
    property
    UIKit
  • 최근 댓글

  • 최근 글

  • 반응형
  • hELLO· Designed By정상우.v4.10.0
Hamp
[ThirdParty] SwiftUI-Shimmer 해석하기
상단으로

티스토리툴바