mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 04:47:13 +08:00 
			
		
		
		
	Generic way of handling tap events
This commit is contained in:
		
				
					committed by
					
						
						renancaraujo
					
				
			
			
				
	
			
			
			
						parent
						
							add2a4fdc8
						
					
				
				
					commit
					ddaa8b296e
				
			@ -50,17 +50,14 @@ mixin Tapable on BaseComponent {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mixin HasTapableComponents on BaseGame {
 | 
			
		||||
  @mustCallSuper
 | 
			
		||||
  void onTapCancel(int pointerId) {
 | 
			
		||||
  void _handleTapEvent(bool Function(Tapable child) tapEventHandler) {
 | 
			
		||||
    for (Component c in components.toList().reversed) {
 | 
			
		||||
      bool shouldContinue = true;
 | 
			
		||||
      if (c is BaseComponent) {
 | 
			
		||||
        shouldContinue = c.propagateToChildren<Tapable>(
 | 
			
		||||
          (child) => child.handleTapCancel(pointerId),
 | 
			
		||||
        );
 | 
			
		||||
        shouldContinue = c.propagateToChildren<Tapable>(tapEventHandler);
 | 
			
		||||
      }
 | 
			
		||||
      if (c is Tapable && shouldContinue) {
 | 
			
		||||
        shouldContinue = c.handleTapCancel(pointerId);
 | 
			
		||||
        shouldContinue = tapEventHandler(c);
 | 
			
		||||
      }
 | 
			
		||||
      if (!shouldContinue) {
 | 
			
		||||
        break;
 | 
			
		||||
@ -68,39 +65,18 @@ mixin HasTapableComponents on BaseGame {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @mustCallSuper
 | 
			
		||||
  void onTapCancel(int pointerId) {
 | 
			
		||||
    _handleTapEvent((Tapable child) => child.handleTapCancel(pointerId));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @mustCallSuper
 | 
			
		||||
  void onTapDown(int pointerId, TapDownDetails details) {
 | 
			
		||||
    for (Component c in components.toList().reversed) {
 | 
			
		||||
      bool shouldContinue = true;
 | 
			
		||||
      if (c is BaseComponent) {
 | 
			
		||||
        shouldContinue = c.propagateToChildren<Tapable>(
 | 
			
		||||
          (child) => child.handleTapDown(pointerId, details),
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
      if (c is Tapable && shouldContinue) {
 | 
			
		||||
        shouldContinue = c.handleTapDown(pointerId, details);
 | 
			
		||||
      }
 | 
			
		||||
      if (!shouldContinue) {
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    _handleTapEvent((Tapable child) => child.handleTapDown(pointerId, details));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @mustCallSuper
 | 
			
		||||
  void onTapUp(int pointerId, TapUpDetails details) {
 | 
			
		||||
    for (Component c in components.toList().reversed) {
 | 
			
		||||
      bool shouldContinue = true;
 | 
			
		||||
      if (c is BaseComponent) {
 | 
			
		||||
        shouldContinue = c.propagateToChildren<Tapable>(
 | 
			
		||||
          (child) => child.handleTapUp(pointerId, details),
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
      if (c is Tapable && shouldContinue) {
 | 
			
		||||
        shouldContinue = c.handleTapUp(pointerId, details);
 | 
			
		||||
      }
 | 
			
		||||
      if (!shouldContinue) {
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    _handleTapEvent((Tapable child) => child.handleTapUp(pointerId, details));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user