Fabric: Codestyle for RCTSurfaceTouchHandler

Summary:
Trivial. I need this to make the next diff readable.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D19221205

fbshipit-source-id: 0f8b608866ea974272901b2b2e208e9cd88c8e0a
This commit is contained in:
Valentin Shergin 2019-12-23 16:54:04 -08:00 коммит произвёл Facebook Github Bot
Родитель 2c40cc714c
Коммит 2c09f65f63
1 изменённых файлов: 36 добавлений и 41 удалений

Просмотреть файл

@ -18,13 +18,14 @@ using namespace facebook::react;
template <size_t size>
class IdentifierPool {
public:
void enqueue(int index) {
public:
void enqueue(int index)
{
usage[index] = false;
}
int dequeue() {
int dequeue()
{
while (true) {
if (!usage[lastIndex]) {
usage[lastIndex] = true;
@ -34,14 +35,14 @@ public:
}
}
void reset() {
void reset()
{
for (int i = 0; i < size; i++) {
usage[i] = false;
}
}
private:
private:
bool usage[size];
int lastIndex;
};
@ -63,19 +64,22 @@ struct ActiveTouch {
__strong UIView<RCTComponentViewProtocol> *componentView = nil;
struct Hasher {
size_t operator()(const ActiveTouch &activeTouch) const {
size_t operator()(const ActiveTouch &activeTouch) const
{
return std::hash<decltype(activeTouch.touch.identifier)>()(activeTouch.touch.identifier);
}
};
struct Comparator {
bool operator()(const ActiveTouch &lhs, const ActiveTouch &rhs) const {
bool operator()(const ActiveTouch &lhs, const ActiveTouch &rhs) const
{
return lhs.touch.identifier == rhs.touch.identifier;
}
};
};
static void UpdateActiveTouchWithUITouch(ActiveTouch &activeTouch, UITouch *uiTouch, UIView *rootComponentView) {
static void UpdateActiveTouchWithUITouch(ActiveTouch &activeTouch, UITouch *uiTouch, UIView *rootComponentView)
{
CGPoint offsetPoint = [uiTouch locationInView:activeTouch.componentView];
CGPoint screenPoint = [uiTouch locationInView:uiTouch.window];
CGPoint pagePoint = [uiTouch locationInView:rootComponentView];
@ -91,7 +95,8 @@ static void UpdateActiveTouchWithUITouch(ActiveTouch &activeTouch, UITouch *uiTo
}
}
static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponentView) {
static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponentView)
{
UIView *componentView = uiTouch.view;
ActiveTouch activeTouch = {};
@ -108,21 +113,20 @@ static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponen
return activeTouch;
}
static BOOL AllTouchesAreCancelledOrEnded(NSSet<UITouch *> *touches) {
static BOOL AllTouchesAreCancelledOrEnded(NSSet<UITouch *> *touches)
{
for (UITouch *touch in touches) {
if (touch.phase == UITouchPhaseBegan ||
touch.phase == UITouchPhaseMoved ||
touch.phase == UITouchPhaseStationary) {
if (touch.phase == UITouchPhaseBegan || touch.phase == UITouchPhaseMoved || touch.phase == UITouchPhaseStationary) {
return NO;
}
}
return YES;
}
static BOOL AnyTouchesChanged(NSSet<UITouch *> *touches) {
static BOOL AnyTouchesChanged(NSSet<UITouch *> *touches)
{
for (UITouch *touch in touches) {
if (touch.phase == UITouchPhaseBegan ||
touch.phase == UITouchPhaseMoved) {
if (touch.phase == UITouchPhaseBegan || touch.phase == UITouchPhaseMoved) {
return YES;
}
}
@ -135,9 +139,10 @@ static BOOL AnyTouchesChanged(NSSet<UITouch *> *touches) {
* This is quite trivial but decent implementation of hasher function
* inspired by this research: https://stackoverflow.com/a/21062520/496389.
*/
template<typename PointerT>
template <typename PointerT>
struct PointerHasher {
constexpr std::size_t operator()(const PointerT &value) const {
constexpr std::size_t operator()(const PointerT &value) const
{
return reinterpret_cast<size_t>(value);
}
};
@ -146,11 +151,8 @@ struct PointerHasher {
@end
@implementation RCTSurfaceTouchHandler {
std::unordered_map<
__unsafe_unretained UITouch *,
ActiveTouch,
PointerHasher<__unsafe_unretained UITouch *>
> _activeTouches;
std::unordered_map<__unsafe_unretained UITouch *, ActiveTouch, PointerHasher<__unsafe_unretained UITouch *>>
_activeTouches;
UIView *_rootComponentView;
IdentifierPool<11> _identifierPool;
@ -173,7 +175,7 @@ struct PointerHasher {
return self;
}
RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action)
RCT_NOT_IMPLEMENTED(-(instancetype)initWithTarget : (id)target action : (SEL)action)
- (void)attachToView:(UIView *)view
{
@ -251,10 +253,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
continue;
}
if (
isEndishEventType &&
event.changedTouches.find(pair.second.touch) != event.changedTouches.end()
) {
if (isEndishEventType && event.changedTouches.find(pair.second.touch) != event.changedTouches.end()) {
continue;
}
@ -294,8 +293,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
[super touchesBegan:touches withEvent:event];
[self _registerTouches:touches];
[self _dispatchActiveTouches:[self _activeTouchesFromTouches:touches]
eventType:RCTTouchEventTypeTouchStart];
[self _dispatchActiveTouches:[self _activeTouchesFromTouches:touches] eventType:RCTTouchEventTypeTouchStart];
if (self.state == UIGestureRecognizerStatePossible) {
self.state = UIGestureRecognizerStateBegan;
@ -309,8 +307,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
[super touchesMoved:touches withEvent:event];
[self _updateTouches:touches];
[self _dispatchActiveTouches:[self _activeTouchesFromTouches:touches]
eventType:RCTTouchEventTypeTouchMove];
[self _dispatchActiveTouches:[self _activeTouchesFromTouches:touches] eventType:RCTTouchEventTypeTouchMove];
self.state = UIGestureRecognizerStateChanged;
}
@ -320,8 +317,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
[super touchesEnded:touches withEvent:event];
[self _updateTouches:touches];
[self _dispatchActiveTouches:[self _activeTouchesFromTouches:touches]
eventType:RCTTouchEventTypeTouchEnd];
[self _dispatchActiveTouches:[self _activeTouchesFromTouches:touches] eventType:RCTTouchEventTypeTouchEnd];
[self _unregisterTouches:touches];
if (AllTouchesAreCancelledOrEnded(event.allTouches)) {
@ -336,8 +332,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
[super touchesCancelled:touches withEvent:event];
[self _updateTouches:touches];
[self _dispatchActiveTouches:[self _activeTouchesFromTouches:touches]
eventType:RCTTouchEventTypeTouchCancel];
[self _dispatchActiveTouches:[self _activeTouchesFromTouches:touches] eventType:RCTTouchEventTypeTouchCancel];
[self _unregisterTouches:touches];
if (AllTouchesAreCancelledOrEnded(event.allTouches)) {
@ -359,8 +354,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
activeTouches.push_back(pair.second);
}
[self _dispatchActiveTouches:activeTouches
eventType:RCTTouchEventTypeTouchCancel];
[self _dispatchActiveTouches:activeTouches eventType:RCTTouchEventTypeTouchCancel];
// Force-unregistering all the touches.
_activeTouches.clear();
@ -382,7 +376,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(__unused UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
- (BOOL)gestureRecognizer:(__unused UIGestureRecognizer *)gestureRecognizer
shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
// Same condition for `failure of` as for `be prevented by`.
return [self canBePreventedByGestureRecognizer:otherGestureRecognizer];