-
Notifications
You must be signed in to change notification settings - Fork 944
/
MDCRippleView.h
176 lines (137 loc) · 6.75 KB
/
MDCRippleView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright 2019-present the Material Components for iOS authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <UIKit/UIKit.h>
API_DEPRECATED_BEGIN("Follow go/material-ios-touch-response, touch response should use system "
"highlighting behavior.",
ios(12, API_TO_BE_DEPRECATED))
// TODO(b/151929968): Delete import of delegate headers when client code has been migrated to no
// longer import delegates as transitive dependencies.
#import "MDCRippleViewDelegate.h"
@protocol MDCRippleViewDelegate;
/**
Convenience naming for the completion blocks the ripple animation provides.
*/
typedef void (^MDCRippleCompletionBlock)(void);
/**
The different possible ripple styles. The ripple can either be bound to the view or not.
- MDCRippleStyleBounded: The ripple is bound to the view.
- MDCRippleStyleUnbounded: The ripple is unbounded and ripples to the size of the smallest circle
that covers the entire rectangular bounds, plus an additional 10 points.
*/
typedef NS_ENUM(NSInteger, MDCRippleStyle) {
MDCRippleStyleBounded = 0,
MDCRippleStyleUnbounded,
};
/**
A UIView that draws and animates the Material Design ripple effect for touch interactions.
The Ripple is a visual flourish consisting of an animated circle with various scale, opacity and
position animations applied simultaneously to give the illusion of ink applied to a paper surface.
Our touch feedback ripple effect is a prominent entity across all our interactable components:
i.e., buttons, cards, tab bars, list items.
There can be multiple riples occurring at the same time, each represented by an MDCRippleLayer.
*/
@interface MDCRippleView : UIView
/**
The ripple view delegate.
*/
@property(nonatomic, weak, nullable) id<MDCRippleViewDelegate> rippleViewDelegate;
/**
The ripple style indicating if the ripple is bounded or unbounded to the view.
*/
@property(nonatomic, assign) MDCRippleStyle rippleStyle;
/**
The ripple's color.
*/
@property(nonatomic, strong, nonnull) UIColor *rippleColor;
/**
The maximum radius the ripple can expand to.
@note This property is ignored if @c rippleStyle is set to @c MDCRippleStyleBounded.
*/
@property(nonatomic, assign) CGFloat maximumRadius;
/**
The ripple color of the currently active ripple.
*/
@property(nonatomic, strong, nonnull) UIColor *activeRippleColor;
/**
When rippleStyle is MDCRippleStyleBounded, this flag affects whether the layer's mask will use
the super view's layer.shadowPath as the mask path.
@note This behavior only takes effect if the ripple view's parent view has a non-nil shadowPath.
@note This behavioral flag will eventually become NO by default and then be deleted. The YES
behavior is undesired because it assumes that the frame of the ripple view always matches the
bounds of the superview. When this assumption is false, such as when the ripple's origin is
non-zero, the ripple's mask tends to be bigger than it should be resulting in an incorrectly
clipped ripple effect. Consider disabling this behavior and explicitly setting a layer mask
instead.
Changing this value to NO does not clear the mask if it was already set.
Default value is YES.
*/
@property(nonatomic, assign) BOOL usesSuperviewShadowLayerAsMask;
/**
A block that is invoked when the @c MDCRippleView receives a call to @c
traitCollectionDidChange:. The block is called after the call to the superclass.
*/
@property(nonatomic, copy, nullable) void (^traitCollectionDidChangeBlock)
(MDCRippleView *_Nonnull ripple, UITraitCollection *_Nullable previousTraitCollection);
/**
Cancels all the existing ripples.
@param animated Whether to animate the cancellation of the ripples or not.
*/
- (void)cancelAllRipplesAnimated:(BOOL)animated
completion:(nullable MDCRippleCompletionBlock)completion;
/**
Fades the ripple in by changing its opacity.
@param animated Whether or not the fade in should be animated or not.
@param completion A completion block called after the completion of the animation.
*/
- (void)fadeInRippleAnimated:(BOOL)animated
completion:(nullable MDCRippleCompletionBlock)completion;
/**
Fades the ripple out by changing its opacity.
@param animated Whether or not the fade in should be animated or not.
@param completion A completion block called after the completion of the animation.
*/
- (void)fadeOutRippleAnimated:(BOOL)animated
completion:(nullable MDCRippleCompletionBlock)completion;
/**
Begins the ripple's touch down animation at the given point. This presents the ripple and leaves it
on the view. If animated, it animates the expanding ripple circle effect.
To then remove the ripple, `beginRippleTouchUpAnimated` needs to be called.
@param point The point to start the ripple animation.
@param animated Whether or not the ripple should be animated or not.
@param completion A completion block called after the completion of the animation.
*/
- (void)beginRippleTouchDownAtPoint:(CGPoint)point
animated:(BOOL)animated
completion:(nullable MDCRippleCompletionBlock)completion;
/**
Begins the ripple's touch up animation. This remopves the ripple from the view. If animated, the
ripple dissolves using an animated opacity change.
@param animated Whether or not the ripple should be animated or not.
@param completion A completion block called after the completion of the animation.
*/
- (void)beginRippleTouchUpAnimated:(BOOL)animated
completion:(nullable MDCRippleCompletionBlock)completion;
/**
Enumerates the given view's subviews for an instance of MDCRippleView and returns it if found, or
creates and adds a new instance of MDCRippleView if not.
This method is a convenience method for adding ripple to an arbitrary view without needing to
subclass the target view. Use this method in situations where you expect there to be many distinct
ripple views in existence for a single ripple touch controller. Example scenarios include:
- Adding ripple to individual collection view/table view cells
This method can be used in your MDCRippleTouchController delegate's
-rippleTouchController:rippleViewAtTouchLocation: implementation.
*/
+ (nonnull MDCRippleView *)injectedRippleViewForView:(nonnull UIView *)view;
@end
API_DEPRECATED_END