-
Notifications
You must be signed in to change notification settings - Fork 6k
iOS platform view opacity #9667
Changes from 10 commits
92d9b3d
b8a9f6f
cf1c701
8583580
740e857
eec1c24
f9373b2
ee78ff9
23c6807
82652cc
a7e3427
ce8bad5
fa898f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,24 @@ | |
|
|
||
| namespace flutter { | ||
|
|
||
| enum MutatorType { clip_rect, clip_rrect, clip_path, transform }; | ||
| enum MutatorType { clip_rect, clip_rrect, clip_path, transform, opacity }; | ||
|
|
||
| // Stores information required for an opacity Mutator. | ||
| // Matches the members in a `OpacityLayer`. | ||
| struct OpacityParams { | ||
| std::reference_wrapper<int> alpha; | ||
| std::reference_wrapper<SkPoint> offset; | ||
|
|
||
| bool operator==(const OpacityParams& other) const { | ||
| return alpha == other.alpha && offset == other.offset; | ||
| } | ||
|
|
||
| bool operator!=(const OpacityParams& other) const { | ||
| return !operator==(other); | ||
| } | ||
|
|
||
| float GetAlphaF() const { return (alpha / 255.0); } | ||
|
||
| }; | ||
|
|
||
| // Stores mutation information like clipping or transform. | ||
| // | ||
|
|
@@ -42,6 +59,9 @@ class Mutator { | |
| case transform: | ||
| matrix_ = other.matrix_; | ||
| break; | ||
| case opacity: | ||
| opacityParams_ = OpacityParams{other.opacityParams_.alpha, | ||
| other.opacityParams_.offset}; | ||
|
||
| default: | ||
| break; | ||
| } | ||
|
|
@@ -53,12 +73,15 @@ class Mutator { | |
| : type_(clip_path), path_(new SkPath(path)) {} | ||
| explicit Mutator(const SkMatrix& matrix) | ||
| : type_(transform), matrix_(matrix) {} | ||
| explicit Mutator(const OpacityParams& opacityParams) | ||
| : type_(opacity), opacityParams_(opacityParams) {} | ||
|
|
||
| const MutatorType& GetType() const { return type_; } | ||
| const SkRect& GetRect() const { return rect_; } | ||
| const SkRRect& GetRRect() const { return rrect_; } | ||
| const SkPath& GetPath() const { return *path_; } | ||
| const SkMatrix& GetMatrix() const { return matrix_; } | ||
| const OpacityParams& GetOpacityParams() const { return opacityParams_; } | ||
|
|
||
| bool operator==(const Mutator& other) const { | ||
| if (type_ != other.type_) { | ||
|
|
@@ -73,6 +96,8 @@ class Mutator { | |
| return *path_ == *other.path_; | ||
| case transform: | ||
| return matrix_ == other.matrix_; | ||
| case opacity: | ||
| return opacityParams_ == other.opacityParams_; | ||
| } | ||
|
|
||
| return false; | ||
|
|
@@ -97,6 +122,8 @@ class Mutator { | |
| SkRect rect_; | ||
| SkRRect rrect_; | ||
| SkMatrix matrix_; | ||
| OpacityParams opacityParams_; | ||
| int alpha_; | ||
| SkPath* path_; | ||
| }; | ||
|
|
||
|
|
@@ -119,6 +146,7 @@ class MutatorsStack { | |
| void PushClipRRect(const SkRRect& rrect); | ||
| void PushClipPath(const SkPath& path); | ||
| void PushTransform(const SkMatrix& matrix); | ||
| void PushOpacity(const OpacityParams& opacityParams); | ||
|
|
||
| // Removes the `Mutator` on the top of the stack | ||
| // and destroys it. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,6 +278,13 @@ | |
| head = clipView; | ||
| break; | ||
| } | ||
| case opacity: | ||
| embedded_view.alpha = (*iter)->GetOpacityParams().GetAlphaF() * embedded_view.alpha; | ||
| CATransform3D transform = | ||
|
||
| CATransform3DMakeTranslation((*iter)->GetOpacityParams().offset.get().fX, | ||
| (*iter)->GetOpacityParams().offset.get().fY, 0); | ||
| head.layer.transform = CATransform3DConcat(head.layer.transform, transform); | ||
| break; | ||
| } | ||
| ++iter; | ||
| } | ||
|
|
@@ -299,6 +306,7 @@ | |
| UIView* touchInterceptor = touch_interceptors_[view_id].get(); | ||
| touchInterceptor.layer.transform = CATransform3DIdentity; | ||
| touchInterceptor.frame = frame; | ||
| touchInterceptor.alpha = 1; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think since we are adding more stuff here and might add even more later, we can have a possible refactoring to make a separate method to do all of these: |
||
|
|
||
| int currentClippingCount = CountClips(params.mutatorsStack); | ||
| int previousClippingCount = clip_count_[view_id]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't read the rest of the PR yet, but looking at this I'm not sure what does an offset means for opacity, should probably add a comment.