blob: c596ca8856c1a36f5a9b31d2c346c64ffe8d67a2 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TAB_GRID_TRANSITIONS_GRID_TRANSITION_LAYOUT_H_
#define IOS_CHROME_BROWSER_UI_TAB_GRID_TRANSITIONS_GRID_TRANSITION_LAYOUT_H_
#import <UIKit/UIKit.h>
@protocol GridToTabTransitionView;
@class GridTransitionActiveItem;
@class GridTransitionItem;
// An encapsulation of information for the layout of a grid of cells that will
// be used in an animated transition. The layout object is composed of layout
// items (see below).
@interface GridTransitionLayout : NSObject
// The inactive items in the layout. |activeItem| and |selectionItem| are not
// in this array.
@property(nonatomic, copy, readonly)
NSArray<GridTransitionItem*>* inactiveItems;
// The item in the layout (if any) that's the 'active' item (the one that will
// expand and contract).
@property(nonatomic, strong, readonly) GridTransitionActiveItem* activeItem;
// An item that shows the selections state (and nothing else) of the active
// item.
@property(nonatomic, strong, readonly) GridTransitionItem* selectionItem;
// The rect, in UIWindow coordinates, that an "expanded" item should occupy.
@property(nonatomic) CGRect expandedRect;
// Creates a new layout object.
// |inactiveItems| should be non-nil, but it may be empty.
// |activeItem| and |selectionItem| may be nil.
+ (instancetype)layoutWithInactiveItems:(NSArray<GridTransitionItem*>*)items
activeItem:(GridTransitionActiveItem*)activeItem
selectionItem:(GridTransitionItem*)selectionItem;
@end
// An encapsulation of information for the layout of a single grid cell.
@interface GridTransitionItem : NSObject
// A view with the desired appearance of the cell for animation. This should
// not be in any view hierarchy when the layout item is created. It should
// otherwise be sized correctly and have the correct appearance.
@property(nonatomic, strong, readonly) UIView* cell;
// The position of |cell| in the grid view, normalized to UIWindow coordinates.
@property(nonatomic, readonly) CGPoint center;
// Creates a new layout item instance with |cell| and |center|. It's the
// responsibility of the caller to normalize |center| to UIWindow coordinates.
// It's an error if |cell| has a superview or is nil.
+ (instancetype)itemWithCell:(UIView*)cell center:(CGPoint)center;
@end
// An extension of GridTransitionItem for an item that will transition between
// 'cell' and 'tab' appearance during the animation.
@interface GridTransitionActiveItem : GridTransitionItem
// A view with the desired appearance of the cell for animation. This should
// not be in any view hierarchy when the layout item is created. It should
// otherwise be sized correctly and have the correct appearance.
@property(nonatomic, strong, readonly) UIView<GridToTabTransitionView>* cell;
// The size of |cell| in the grid.
@property(nonatomic, readonly) CGSize size;
// Creates a new active item instance with |cell|, |center| and |size|.
+ (instancetype)itemWithCell:(UIView<GridToTabTransitionView>*)cell
center:(CGPoint)center
size:(CGSize)size;
// Populate the |cell| view of the reciever by extracting snapshots from |view|,
// using |rect| to define (in |view|'s coordinates) the main tab view, with any
// space above and below |rect| being the top and bottom tab views.
- (void)populateWithSnapshotsFromView:(UIView*)view middleRect:(CGRect)rect;
@end
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TRANSITIONS_GRID_TRANSITION_LAYOUT_H_