Skip to content

Commit

Permalink
VLCSlider: fix padding behaviour for different types of devices
Browse files Browse the repository at this point in the history
In some cases, the padding could lead to behave weirdly on small devices.

Therefore, this will ajust the padding depending on the device "category"
defined by the safe area and iPads.

Additionally, this will increase the hit size for iPads.
  • Loading branch information
Mikanbu committed Oct 29, 2021
1 parent 227f430 commit 82e8fbe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions SharedSources/UIDevice+VLC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
return UIScreen.screens.count > 1
}

@objc(VLCDeviceHasSafeArea)
static var hasSafeArea: Bool {
if #available(iOS 11.0, *) {
let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
Expand Down
17 changes: 16 additions & 1 deletion Sources/VLCSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*****************************************************************************/

#import "VLCSlider.h"
#import "VLC-Swift.h"

@implementation VLCOBSlider

Expand All @@ -23,7 +24,21 @@ - (void)awakeFromNib

- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value
{
return CGRectInset([super thumbRectForBounds:bounds trackRect:rect value:value], -5 , -5);
// By default do not set padding for small devices such as ipod.
CGFloat padding = 0;

// Add padding to safe area devices.
if ([UIDevice VLCDeviceHasSafeArea]) {
padding = -5;
}

// Add even more padding to ipads.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
padding = -10;
}

return CGRectInset([super thumbRectForBounds:bounds trackRect:rect value:value],
padding , padding);
}

@end
Expand Down

0 comments on commit 82e8fbe

Please sign in to comment.