RxSwiftCommunity/RxGesture hiện có 1.4k sao trên GitHub, viết chủ yếu bằng Swift. RxSwift reactive wrapper for view gestures
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
To run the example project, clone the repo, in the Example folder open RxGesture.xcworkspace.
You might need to run pod install from the Example directory first.
RxGesture allows you to easily turn any view into a tappable or swipeable control like so:
view.rx
.tapGesture()
.when(.recognized)
.subscribe(onNext: { _ in
//react to taps
})
.disposed(by: stepBag)
You can also react to more than one gesture. For example to dismiss a photo preview you might want to do that when the user taps it, or swipes up or down:
rx.gesture is defined as Observable<G> where G is the actual type of the gesture recognizer so what it emits is the gesture recognizer itself (handy if want to call methods like asLocation(in view:) or asTranslation(in view:))
ℹ️ If you use a gesture recognizer alone, prefer the view.rx.fooGesture() syntax over view.rx.anyGesture(.foo()) because it returns the concrete UIGestureRecognizer subclass and avoid you to cast it in subscribe().
Filtering State
By default, there is no filter on the state of the gesture recognizer. That means that you will always receive a first event with the initial state of the gesture recognizer (almost always .possible).
Here are the preferred states that can be used for each kind of gestures (iOS and macOS):
If you are observing multiple gestures at once, you can use the .when() operator if you want to filter against the same state for all gesture recognizers, or use the tuple syntax for individual filtering:
view.rx
.anyGesture(.tap(), .swipe([.up, .down]))
.when(.recognized)
.subscribe(onNext: { gesture in
// Called whenever a tap, a swipe-up or a swipe-down is recognized (state == .recognized)
})
.disposed(by: bag)
view.rx
.anyGesture(
(.tap(), when: .recognized),
(.pan(), when: .ended)
)
.subscribe(onNext: { gesture in
// Called whenever:
// - a tap is recognized (state == .recognized)
// - or a pan is ended (state == .ended)
})
.disposed(by: bag)
The demo app includes examples for all recognizers ➡️ iOS, macOS.
Delegate customization
Lightweight customization
Each gesture recognizer has a default RxGestureRecognizerDelegate. It allows you to customize every delegate method using a policy:
.always will return true to the corresponding delegate method
.never will return false to the corresponding delegate method
.custom takes an associated closure that will be executed to return a value to the corresponding delegate method
Here are the available policies with their corresponding delegate method:
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/RxSwiftCommunity/RxGesture là nguồn chính thức.
RxSwiftCommunity/RxGesture có phải mã nguồn mở không?
Có — RxSwiftCommunity/RxGesture phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/RxSwiftCommunity/RxGesture.
RxSwiftCommunity/RxGesture là gì?
RxSwiftCommunity/RxGesture (RxSwiftCommunity/RxGesture) là dự án Swift trên GitHub. Theo mô tả gốc: RxSwift reactive wrapper for view gestures
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về RxGesture?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về RxGesture.