Skip to content

Conversation

@orukahairuka
Copy link
Contributor

  • iOSでのグラデーションカラーを実装

@orukahairuka orukahairuka requested a review from Copilot August 18, 2025 06:47
@orukahairuka orukahairuka changed the title Gradation color feat: gradation-color Aug 18, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements gradient color support for iOS, adding the ability to render linear gradients in addition to solid colors for backgrounds, borders, and text.

  • Adds new ColorValue types to support both solid colors and linear gradients
  • Updates color parsing logic to handle the new gradient format while maintaining backward compatibility
  • Extends border and background configuration functions to apply gradient layers

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ios/Nativebrik/Nativebrik/util/utils.swift Implements gradient color parsing, layer management, and configuration functions
ios/Nativebrik/Nativebrik/generated.swift Adds new gradient-related data structures and enums
ios/Nativebrik/Nativebrik/component/renderer/text.swift Updates text color handling to support new ColorValue format
flutter/nativebrik_bridge/lib/schema/generated.dart Adds gradient support to Dart schema (auto-generated)
android/nativebrik/src/main/java/com/nativebrik/sdk/schema/generated.kt Adds gradient support to Android schema (auto-generated)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

view.layer.backgroundColor = color.cgColor
view.layer.sublayers?.filter { $0.name == "gradient-layer" }.forEach { $0.removeFromSuperlayer() }
case .linearGradient(let gradientLayer):
print("DEBUG: Applying gradient layer with bounds: \(view.bounds)")
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

Debug print statements should not be left in production code. Consider using proper logging or removing this statement.

Suggested change
print("DEBUG: Applying gradient layer with bounds: \(view.bounds)")

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

修正した


if !colors.isEmpty {
gradientLayer.colors = colors
gradientLayer.locations = locations.count == colors.count ? locations : nil
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

[nitpick] The gradient stop position calculation uses a complex formula that may not distribute colors evenly. Consider simplifying this logic or adding a comment explaining the intended behavior.

Suggested change
gradientLayer.locations = locations.count == colors.count ? locations : nil
positionsSpecified.append(true)
} else {
positionsSpecified.append(false)
}
}
}
// Only set locations if all or none of the stops have explicit positions.
// If all have positions, use them. If none, distribute evenly. If mixed, let Core Animation handle it.
if !colors.isEmpty {
gradientLayer.colors = colors
if positionsSpecified.allSatisfy({ $0 }) && locations.count == colors.count {
// All stops have explicit positions
gradientLayer.locations = locations
} else if positionsSpecified.allSatisfy({ !$0 }) {
// None have explicit positions, distribute evenly
let count = colors.count
if count > 1 {
let evenLocations = (0..<count).map { NSNumber(value: Float($0) / Float(count - 1)) }
gradientLayer.locations = evenLocations
} else {
gradientLayer.locations = nil
}
} else {
// Mixed: let Core Animation distribute stops (do not set locations)
gradientLayer.locations = nil
}

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

提案されたものが複雑だと思われるため、対応しない

@orukahairuka orukahairuka changed the title feat: gradation-color feat: ios-gradation-color Aug 18, 2025
@orukahairuka orukahairuka changed the title feat: ios-gradation-color feat(ios): add gradation color support Aug 18, 2025
@orukahairuka orukahairuka requested a review from t-jimbo August 18, 2025 06:59
orukahairuka and others added 4 commits August 19, 2025 16:08
- Add gradient border support for simple border cases
- Add view.clipsToBounds to prevent content overflow
- Properly set gradient layer frame to match view bounds
- Update both configureBorder and configureBorderWithRawData functions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@RyosukeCla
Copy link
Collaborator

@orukahairuka generated のコードなんですけど、android と flutter の方は別の PR の方で commit してくださーい!!

@orukahairuka
Copy link
Contributor Author

@RyosukeCla
generate.dartとgenerate.ktの差分を削除しました!

@RyosukeCla
Copy link
Collaborator

@orukahairuka nativebrik 本体の方の PR が固まってきてから、もう一度確認します!

@orukahairuka
Copy link
Contributor Author

@t-jimbo
レビューお願いします!


// Calculate direction vector (CSS coordinate system)
let dx = sin(radians)
let dy = -cos(radians) // Y軸を反転(CSSは上が負、iOSは下が正)
Copy link
Collaborator

Choose a reason for hiding this comment

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

コメント英語にしてくださーい!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

英語にしました!

// CAGradientLayer: (0,0) is top-left, (1,1) is bottom-right

// Convert normalized value to radians
let degrees = angle * 360.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

angle が [0, 1] の範囲を超えてたら [0,1]にclipしてほしいです!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

 let clippedAngle = max(0, min(1, angle))
        
        // Convert normalized value to radians
        let degrees = clippedAngle * 360.0

対応しました!

colors.append(parseColorToCGColor(color))

if let position = stop.position {
locations.append(NSNumber(value: position))
Copy link
Collaborator

Choose a reason for hiding this comment

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

position も [0,1]でclipしてください!

Copy link
Contributor Author

@orukahairuka orukahairuka Aug 28, 2025

Choose a reason for hiding this comment

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

対応しました!

@orukahairuka
Copy link
Contributor Author

@RyosukeCla 修正したので、レビューお願いします🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants