Skip to content

New SwiftUI Modifiers Implementation ​

This document explains the implementation of two new SwiftUI modifiers in TachUI:

1. .resizable() Modifier ​

Purpose ​

The .resizable() modifier makes images resizable, allowing them to scale to fit their container. In SwiftUI, this is commonly used with Image views to make them scale appropriately.

Implementation Details ​

  • Class: ResizableModifier in base.ts
  • Type: Appearance modifier
  • Priority: APPEARANCE (200)
  • Functionality: Sets object-fit: fill on image elements

Usage ​

typescript
Image("my-photo.jpg")
  .modifier
  .resizable()
  .frame(200, 150)
  .build()

CSS Equivalent ​

css
img {
  object-fit: fill;
}

2. .textCase() Alias ​

Purpose ​

.textCase() is an alias for the existing .textTransform() modifier, providing API parity with SwiftUI's .textCase() modifier.

Implementation Details ​

  • Function: textCase() in typography.ts
  • Type: Typography modifier
  • Functionality: Calls textTransform() with the same parameters

Usage ​

typescript
Text("Hello World")
  .modifier
  .textCase('uppercase')  // Same as .textTransform('uppercase')
  .build()

Supported Values ​

  • 'none' - No transformation
  • 'uppercase' - All uppercase
  • 'lowercase' - All lowercase
  • 'capitalize' - First letter of each word capitalized

CSS Equivalent ​

css
.text {
  text-transform: uppercase; /* or lowercase, capitalize, none */
}

Implementation Files ​

  1. base.ts - Added ResizableModifier class
  2. builder.ts - Added .resizable() method to ModifierBuilderImpl
  3. typography.ts - Added textCase() alias function
  4. index.ts - Exported new modifier and alias
  5. types.ts - Added method signatures to ModifierBuilder interface
  6. __tests__/new-modifiers.test.ts - Test suite for new modifiers
  7. apps/examples/new-modifiers-demo.ts - Usage examples

Testing ​

The new modifiers have been tested with:

  • Basic functionality tests
  • Integration with existing modifier system
  • Edge cases (non-image elements for resizable)

All tests pass, confirming that the new modifiers work correctly with the existing TachUI modifier system.

Released under the MPL-2.0 License.