Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 5 additions & 45 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Benchmark APIs (`measurePerformance`, `benchmarkScalingOperations`) are now `#if DEBUG`-only.

### Dependencies
- Added [apple/swift-atomics](https://github.com/apple/swift-atomics) for the lock-free snapshot.
- One dependency: [apple/swift-atomics](https://github.com/apple/swift-atomics), used for the lock-free scale-factor snapshot.

## [1.0.0] - 2025-01-XX

### Added
- **Core ScreenUtil class** with singleton pattern for responsive screen adaptation
- **Screen dimension properties**: `screenWidth`, `screenHeight`, `scaleWidth`, `scaleHeight`, `scaleText`
- **Safe area support**: `topSafeArea`, `bottomSafeArea`, `statusBarHeight`
- **Device information**: `pixelRatio` for device pixel density
- **Configuration methods**:
- `setDesignSize(width:height:)` - Set reference design dimensions
- `setMinTextAdapt(_:)` - Enable/disable minimum text adaptation
- `setSplitScreenMode(_:)` - Enable/disable split screen support
- `setFontResolver(_:)` - Custom font scaling resolver
- `refresh()` - Manual screen dimension refresh
- **CGFloat extensions** for easy scaling:
- `.scaleWidth` - Scale by width factor
- `.scaleHeight` - Scale by height factor
- `.scaleText` - Scale for text (minimum factor)
- `.scale(by:)` - Scale by custom factor
- **SwiftUI support** with view modifiers and extensions
- **Orientation handling** with automatic updates
- **iOS 12.0+ and tvOS 12.0+ support**
- **Swift 6.1+ compatibility**
- **Comprehensive unit tests** for all core functionality
- **Apache 2.0 license** for open source distribution
- **Complete documentation** with README and API reference

### Technical Details
- **Platform Support**: iOS 12.0+, tvOS 12.0+
- **Swift Version**: 6.1+
- **Xcode Version**: 15.0+
- **Architecture**: Singleton pattern with thread-safe implementation
- **Performance**: Optimized for minimal overhead and efficient scaling calculations

### Documentation
- Complete README.md with installation and usage examples
- API reference with all public methods and properties
- Code examples for both UIKit and SwiftUI integration
- Contributing guidelines and license information

---

## Version History

- **1.0.0** - Initial release with core responsive design functionality
### Notes
- Pre-1.0: no version has been tagged yet, and the public API is still changing.
The current state is the platform-isolated Swift 6 engine described above; the
next tagged release will become `1.0.0`.
5 changes: 3 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ScreenUtil

Responsive screen-adaptation library for Apple platforms. Scales UI from a fixed design size (e.g. 375×812 from Figma) to the real device. Inspired by `flutter_screenutil`. Pure Swift, zero dependencies. Builds on iOS / macOS / tvOS / watchOS.
Responsive screen-adaptation library for Apple platforms. Scales UI from a fixed design size (e.g. 375×812 from Figma) to the real device. Inspired by `flutter_screenutil`. Pure Swift, one dependency ([apple/swift-atomics](https://github.com/apple/swift-atomics), for the lock-free scale-factor snapshot). Builds on iOS 15 / macOS 12 / tvOS 15 / watchOS 8.

This file orients code-review and cleanup work: it maps the code, marks the public contract that must not break, and records the rules that keep the package clean.

Expand Down Expand Up @@ -35,6 +35,7 @@ Organizing rule: **one platform = one place.** Everything outside `UIKit/` and `
Anything not reachable from this set is a removal/merge candidate.

- `ScreenUtil.shared` + `configure(with:)` — singleton, configured once at launch.
- `refreshMetrics()` — `@MainActor` rebuild of the snapshot (manual refresh, e.g. macOS window resize).
- Numeric scaling: `.w .h .sp .r .sw .sh`.
- `ScreenUtilConfiguration` (+ presets) and `ScalingLimits`.
- `FastScale` / `withFastScale`, `BatchScaler` / `withBatchScaler`.
Expand All @@ -43,7 +44,7 @@ Anything not reachable from this set is a removal/merge candidate.

## Review Checklist (when editing)

- Keep **zero dependencies** — `Package.swift` `dependencies: []` stays empty.
- Keep **exactly one dependency** — only `apple/swift-atomics` (for the atomic `Snapshot`). Don't add others; don't remove it (it's what makes reads lock-free and `ScreenUtil` `Sendable` without `@unchecked`).
- **One platform = one place**: UIKit code only under `UIKit/` (or `#if canImport(UIKit)` blocks); SwiftUI only under `SwiftUI/`. Never bare `import UIKit` in cross-platform files — breaks macOS.
- Builds under `-strict-concurrency=complete` — no new concurrency warnings.
- `ScreenUtil` is compiler-verified `Sendable` (atomic `Snapshot`; no `@unchecked`). New shared state must be `Sendable` / atomic.
Expand Down
38 changes: 22 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ We welcome pull requests! Please follow these guidelines:

### Prerequisites

- Xcode 15.0+
- iOS 12.0+ / tvOS 12.0+ simulator or device
- Swift 6.1+
- Xcode 16.0+
- Swift 6.0 toolchain (the package builds in Swift 6 language mode)
- A simulator or device on iOS 15.0+ / macOS 12.0+ / tvOS 15.0+ / watchOS 8.0+

### Getting Started

Expand All @@ -82,31 +82,37 @@ We welcome pull requests! Please follow these guidelines:

### Project Structure

Platform-isolated layout — anything outside `UIKit/` and `SwiftUI/` is pure
cross-platform (Foundation + CoreGraphics only), which keeps the macOS build safe.

```
ScreenUtil/
├── Package.swift # Package configuration
├── Sources/
│ └── ScreenUtil/
│ ├── ScreenUtil.swift # Main ScreenUtil class
│ ├── Extensions/ # CGFloat extensions
│ └── SwiftUI/ # SwiftUI support
└── Tests/
└── ScreenUtilTests/ # Unit tests
├── Package.swift # Package configuration (one dependency: swift-atomics)
├── Sources/ScreenUtil/
│ ├── Core/ # ScreenUtil engine, configuration, ScaleType, limits, metrics
│ ├── Internal/ # Atomic Snapshot, scale-factor cache, logging
│ ├── Metrics/ # ScreenDimensions, DeviceType
│ ├── Scaling/ # Numeric/CGGeometry extensions, FastScale, BatchScaler
│ ├── UIKit/ # UIFont / UIView / UIEdgeInsets helpers (#if canImport(UIKit))
│ ├── SwiftUI/ # EnvironmentValues.screenUtil
│ └── Debug/ # ScreenUtilDebug
├── Tests/ScreenUtilTests/ # Unit tests (Core / Scaling / SwiftUI / Debug / Performance)
└── Examples/ # Runnable SwiftUI + UIKit demo apps (XcodeGen)
```

## Coding Standards

### Swift Style Guide

We follow the [Swift API Design Guidelines](https://www.swift.org/documentation/api-design-guidelines/) and use SwiftLint for consistency.
We follow the [Swift API Design Guidelines](https://www.swift.org/documentation/api-design-guidelines/).

### Code Formatting

- Use **4 spaces** for indentation (no tabs)
- Maximum line length: **120 characters**
- Use **camelCase** for variables and functions
- Use **PascalCase** for types and protocols
- Use **snake_case** for file names
- Use **PascalCase** for types, protocols, **and file names** (e.g. `ScreenUtil.swift`, `ScaleType.swift`)
- Each file starts with an Xcode-style header comment ending `Created by Dicky Darmawan on DD/MM/YY`

### Documentation

Expand Down Expand Up @@ -192,9 +198,9 @@ final class ScreenUtilTests: XCTestCase {

### Before Submitting

1. **Ensure tests pass** locally
1. **Ensure tests pass** locally (`swift test`, and `swift test --sanitize=thread` for concurrency changes)
2. **Update documentation** if needed
3. **Check code formatting** with SwiftLint
3. **Check code formatting** against the style guide above
4. **Self-review** your changes

### Pull Request Template
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Examples/image/UIKit - iPhone 12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading