Skip to content

Commit ed02ac9

Browse files
committed
Add disabling/enabling shake gesture to toggle visiblity
1 parent 83f06c0 commit ed02ac9

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

Sources/EYLogTextView/EYLogTextView.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
*/
3131
+ (void)toggle;
3232

33+
/**
34+
* Disables toggling the shared EYLogTextView instance visibility on device shake.
35+
*/
36+
+ (void)disableShakeToggle;
37+
38+
/**
39+
* Enables toggling the shared EYLogTextView instance visibility on device shake.
40+
*/
41+
+ (void)enableShakeToggle;
42+
3343
/**
3444
* Clears the text on the shared EYLogTextView instance.
3545
*/

Sources/EYLogTextView/EYLogTextView.m

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
#pragma mark - UIResponder swizzle for detecting device shake
1313

14+
@interface EYLogTextView ()
15+
+ (void)toggleIfAllowed;
16+
@end
17+
1418
@implementation UIResponder (EYLogTextView)
1519

1620
+ (void)setupShakeMotionDetection
@@ -26,7 +30,7 @@ - (void)EYLogTextView_motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)ev
2630
{
2731
[self EYLogTextView_motionEnded:motion withEvent:event];
2832

29-
[EYLogTextView toggle];
33+
[EYLogTextView toggleIfAllowed];
3034
}
3135

3236
@end
@@ -134,6 +138,7 @@ - (void)present
134138

135139
@interface EYLogTextView ()
136140
@property BOOL shouldStayOnTop;
141+
@property BOOL shouldToggleOnShake;
137142
@end
138143

139144

@@ -175,6 +180,27 @@ + (void)toggle
175180
}
176181

177182

183+
+ (void)toggleIfAllowed
184+
{
185+
if (EYLogTextView.sharedInstance.shouldToggleOnShake)
186+
{
187+
[EYLogTextView.sharedInstance toggleWithAnimation];
188+
}
189+
}
190+
191+
192+
+ (void)disableShakeToggle
193+
{
194+
EYLogTextView.sharedInstance.shouldToggleOnShake = NO;
195+
}
196+
197+
198+
+ (void)enableShakeToggle
199+
{
200+
EYLogTextView.sharedInstance.shouldToggleOnShake = YES;
201+
}
202+
203+
178204
+ (void)clear
179205
{
180206
EYLogTextView.sharedInstance.text = @"";

0 commit comments

Comments
 (0)