-
Notifications
You must be signed in to change notification settings - Fork 929
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support pinch, double tap and rotation gestures on iOS (#3130)
This is off by default on iOS. Note that pinch delta may be NaN. Co-authored-by: Mads Marquart <[email protected]>
- Loading branch information
Showing
10 changed files
with
362 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
use icrate::Foundation::{CGFloat, NSInteger, NSObject, NSUInteger}; | ||
use objc2::{ | ||
encode::{Encode, Encoding}, | ||
extern_class, extern_methods, mutability, ClassType, | ||
}; | ||
|
||
// https://developer.apple.com/documentation/uikit/uigesturerecognizer | ||
extern_class!( | ||
#[derive(Debug, PartialEq, Eq, Hash)] | ||
pub(crate) struct UIGestureRecognizer; | ||
|
||
unsafe impl ClassType for UIGestureRecognizer { | ||
type Super = NSObject; | ||
type Mutability = mutability::InteriorMutable; | ||
} | ||
); | ||
|
||
extern_methods!( | ||
unsafe impl UIGestureRecognizer { | ||
#[method(state)] | ||
pub fn state(&self) -> UIGestureRecognizerState; | ||
} | ||
); | ||
|
||
unsafe impl Encode for UIGestureRecognizer { | ||
const ENCODING: Encoding = Encoding::Object; | ||
} | ||
|
||
// https://developer.apple.com/documentation/uikit/uigesturerecognizer/state | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub struct UIGestureRecognizerState(NSInteger); | ||
|
||
unsafe impl Encode for UIGestureRecognizerState { | ||
const ENCODING: Encoding = NSInteger::ENCODING; | ||
} | ||
|
||
#[allow(dead_code)] | ||
impl UIGestureRecognizerState { | ||
pub const Possible: Self = Self(0); | ||
pub const Began: Self = Self(1); | ||
pub const Changed: Self = Self(2); | ||
pub const Ended: Self = Self(3); | ||
pub const Cancelled: Self = Self(4); | ||
pub const Failed: Self = Self(5); | ||
} | ||
|
||
// https://developer.apple.com/documentation/uikit/uipinchgesturerecognizer | ||
extern_class!( | ||
#[derive(Debug, PartialEq, Eq, Hash)] | ||
pub(crate) struct UIPinchGestureRecognizer; | ||
|
||
unsafe impl ClassType for UIPinchGestureRecognizer { | ||
type Super = UIGestureRecognizer; | ||
type Mutability = mutability::InteriorMutable; | ||
} | ||
); | ||
|
||
extern_methods!( | ||
unsafe impl UIPinchGestureRecognizer { | ||
#[method(scale)] | ||
pub fn scale(&self) -> CGFloat; | ||
|
||
#[method(velocity)] | ||
pub fn velocity(&self) -> CGFloat; | ||
} | ||
); | ||
|
||
unsafe impl Encode for UIPinchGestureRecognizer { | ||
const ENCODING: Encoding = Encoding::Object; | ||
} | ||
|
||
// https://developer.apple.com/documentation/uikit/uirotationgesturerecognizer | ||
extern_class!( | ||
#[derive(Debug, PartialEq, Eq, Hash)] | ||
pub(crate) struct UIRotationGestureRecognizer; | ||
|
||
unsafe impl ClassType for UIRotationGestureRecognizer { | ||
type Super = UIGestureRecognizer; | ||
type Mutability = mutability::InteriorMutable; | ||
} | ||
); | ||
|
||
extern_methods!( | ||
unsafe impl UIRotationGestureRecognizer { | ||
#[method(rotation)] | ||
pub fn rotation(&self) -> CGFloat; | ||
|
||
#[method(velocity)] | ||
pub fn velocity(&self) -> CGFloat; | ||
} | ||
); | ||
|
||
unsafe impl Encode for UIRotationGestureRecognizer { | ||
const ENCODING: Encoding = Encoding::Object; | ||
} | ||
|
||
// https://developer.apple.com/documentation/uikit/uitapgesturerecognizer | ||
extern_class!( | ||
#[derive(Debug, PartialEq, Eq, Hash)] | ||
pub(crate) struct UITapGestureRecognizer; | ||
|
||
unsafe impl ClassType for UITapGestureRecognizer { | ||
type Super = UIGestureRecognizer; | ||
type Mutability = mutability::InteriorMutable; | ||
} | ||
); | ||
|
||
extern_methods!( | ||
unsafe impl UITapGestureRecognizer { | ||
#[method(setNumberOfTapsRequired:)] | ||
pub fn setNumberOfTapsRequired(&self, number_of_taps_required: NSUInteger); | ||
|
||
#[method(setNumberOfTouchesRequired:)] | ||
pub fn setNumberOfTouchesRequired(&self, number_of_touches_required: NSUInteger); | ||
} | ||
); | ||
|
||
unsafe impl Encode for UITapGestureRecognizer { | ||
const ENCODING: Encoding = Encoding::Object; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.