Various fixes

This commit is contained in:
Ilya Laktyushin 2022-12-18 00:37:53 +04:00
parent 01fc86ebbc
commit c7532e61e0
9 changed files with 91 additions and 41 deletions

View File

@ -321,6 +321,7 @@ private final class DrawingScreenComponent: CombinedComponent {
typealias EnvironmentType = ViewControllerComponentContainer.Environment
let context: AccountContext
let isAvatar: Bool
let present: (ViewController) -> Void
let updateState: ActionSlot<DrawingView.NavigationState>
let updateColor: ActionSlot<DrawingColor>
@ -341,6 +342,7 @@ private final class DrawingScreenComponent: CombinedComponent {
init(
context: AccountContext,
isAvatar: Bool,
present: @escaping (ViewController) -> Void,
updateState: ActionSlot<DrawingView.NavigationState>,
updateColor: ActionSlot<DrawingColor>,
@ -359,6 +361,7 @@ private final class DrawingScreenComponent: CombinedComponent {
dismissFastColorPicker: @escaping () -> Void
) {
self.context = context
self.isAvatar = isAvatar
self.present = present
self.updateState = updateState
self.updateColor = updateColor
@ -381,6 +384,9 @@ private final class DrawingScreenComponent: CombinedComponent {
if lhs.context !== rhs.context {
return false
}
if lhs.isAvatar != rhs.isAvatar {
return false
}
return true
}
@ -1635,7 +1641,7 @@ private final class DrawingScreenComponent: CombinedComponent {
animation: LottieAnimationComponent.AnimationItem(
name: "media_backToCancel",
mode: .animating(loop: false),
range: isEditingSize || animatingOut ? (0.5, 1.0) : (0.0, 0.5)
range: isEditingSize || animatingOut || component.isAvatar ? (0.5, 1.0) : (0.0, 0.5)
),
colors: ["__allcolors__": .white],
size: CGSize(width: 33.0, height: 33.0)
@ -2111,7 +2117,9 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
buttonView.layer.animateScale(from: 1.0, to: 0.01, duration: 0.3)
}
if let view = self.componentHost.findTaggedView(tag: toolsTag) as? ToolsComponent.View {
view.animateOut(completion: {})
view.animateOut(completion: {
completion()
})
}
if let view = self.componentHost.findTaggedView(tag: modeTag) as? ModeAndSizeComponent.View {
view.animateOut()
@ -2131,6 +2139,9 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
}
func containerLayoutUpdated(layout: ContainerViewLayout, animateOut: Bool = false, transition: Transition) {
guard let controller = self.controller else {
return
}
let isFirstTime = self.validLayout == nil
self.validLayout = layout
@ -2162,6 +2173,7 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
component: AnyComponent(
DrawingScreenComponent(
context: self.context,
isAvatar: controller.isAvatar,
present: { [weak self] c in
self?.controller?.present(c, in: .window(.root))
},
@ -2382,15 +2394,17 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
private let context: AccountContext
private let size: CGSize
private let originalSize: CGSize
private let isAvatar: Bool
public var requestDismiss: (() -> Void)!
public var requestApply: (() -> Void)!
public var getCurrentImage: (() -> UIImage?)!
public init(context: AccountContext, size: CGSize, originalSize: CGSize) {
public init(context: AccountContext, size: CGSize, originalSize: CGSize, isAvatar: Bool) {
self.context = context
self.size = size
self.originalSize = originalSize
self.isAvatar = isAvatar
super.init(navigationBarPresentationData: nil)
@ -2416,6 +2430,10 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
required public init(coder: NSCoder) {
preconditionFailure()
}
deinit {
print()
}
override public func loadDisplayNode() {
self.displayNode = Node(controller: self, context: self.context)

View File

@ -136,7 +136,7 @@
- (UIView<TGPhotoSolidRoundedButtonView> *)solidRoundedButton:(NSString *)title action:(void(^)(void))action;
- (id<TGPhotoDrawingAdapter>)drawingAdapter:(CGSize)size originalSize:(CGSize)originalSize;
- (id<TGPhotoDrawingAdapter>)drawingAdapter:(CGSize)size originalSize:(CGSize)originalSize isAvatar:(bool)isAvatar;
- (UIView<TGPhotoDrawingEntitiesView> *)drawingEntitiesViewWithSize:(CGSize)size;

View File

@ -65,6 +65,7 @@ typedef enum
- (void)setEditButtonsHighlighted:(TGPhotoEditorTab)buttons;
- (void)setEditButtonsDisabled:(TGPhotoEditorTab)buttons;
- (void)setCenterButtonsHidden:(bool)hidden animated:(bool)animated;
- (void)setAllButtonsHidden:(bool)hidden animated:(bool)animated;
- (void)setCancelDoneButtonsHidden:(bool)hidden animated:(bool)animated;

View File

@ -897,7 +897,7 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel
_coverLabel.frame = CGRectMake(floor((_portraitToolsWrapperView.frame.size.width - _coverLabel.frame.size.width) / 2.0), CGRectGetMaxY(_scrubberView.frame) + 6.0, _coverLabel.frame.size.width, _coverLabel.frame.size.height);
_titleLabel.frame = CGRectMake(screenEdges.left + floor((referenceSize.width - _titleLabel.frame.size.width) / 2.0), screenEdges.top + floor((44.0 - _titleLabel.frame.size.height) / 2.0), _titleLabel.frame.size.width, _titleLabel.frame.size.height);
_subtitleLabel.frame = CGRectMake(screenEdges.left + floor((referenceSize.width - _subtitleLabel.frame.size.width) / 2.0), screenEdges.bottom - 56.0 - buttonSize.height - subtitleSize.height - 20.0, subtitleSize.width, subtitleSize.height);
_subtitleLabel.frame = CGRectMake(screenEdges.left + floor((referenceSize.width - subtitleSize.width) / 2.0), screenEdges.bottom - 56.0 - buttonSize.height - subtitleSize.height - 20.0, subtitleSize.width, subtitleSize.height);
_cancelButton.frame = CGRectMake(screenEdges.left + 16.0, screenEdges.top + floor((44.0 - _cancelButton.frame.size.height) / 2.0), _cancelButton.frame.size.width, _cancelButton.frame.size.height);

View File

@ -12,7 +12,7 @@
@property (nonatomic, copy) void (^requestDismiss)(void);
@property (nonatomic, copy) void (^requestApply)(void);
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView entitiesView:(UIView<TGPhotoDrawingEntitiesView> *)entitiesView stickersContext:(id<TGPhotoPaintStickersContext>)stickersContext;
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView entitiesView:(UIView<TGPhotoDrawingEntitiesView> *)entitiesView stickersContext:(id<TGPhotoPaintStickersContext>)stickersContext isAvatar:(bool)isAvatar;
- (TGPaintingData *)paintingData;

View File

@ -76,7 +76,7 @@ const CGSize TGPhotoPaintingMaxSize = { 2560.0f, 2560.0f };
@implementation TGPhotoDrawingController
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView entitiesView:(UIView<TGPhotoDrawingEntitiesView> *)entitiesView stickersContext:(id<TGPhotoPaintStickersContext>)stickersContext
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView entitiesView:(UIView<TGPhotoDrawingEntitiesView> *)entitiesView stickersContext:(id<TGPhotoPaintStickersContext>)stickersContext isAvatar:(bool)isAvatar
{
self = [super initWithContext:context];
if (self != nil)
@ -85,7 +85,7 @@ const CGSize TGPhotoPaintingMaxSize = { 2560.0f, 2560.0f };
_stickersContext = stickersContext;
CGSize size = TGScaleToSize(photoEditor.originalSize, [TGPhotoDrawingController maximumPaintingSize]);
_drawingAdapter = [_stickersContext drawingAdapter:size originalSize:photoEditor.originalSize];
_drawingAdapter = [_stickersContext drawingAdapter:size originalSize:photoEditor.originalSize isAvatar:isAvatar];
_interfaceController = (UIViewController<TGPhotoDrawingInterfaceController> *)_drawingAdapter.interfaceController;
__weak TGPhotoDrawingController *weakSelf = self;
@ -117,6 +117,10 @@ const CGSize TGPhotoPaintingMaxSize = { 2560.0f, 2560.0f };
return self;
}
- (void)dealloc {
NSLog(@"");
}
- (void)loadView
{
[super loadView];
@ -450,27 +454,10 @@ const CGSize TGPhotoPaintingMaxSize = { 2560.0f, 2560.0f };
#pragma mark - Transitions
- (void)transitionIn
{
// _portraitSettingsView.layer.shouldRasterize = true;
// _landscapeSettingsView.layer.shouldRasterize = true;
//
// [UIView animateWithDuration:0.3f animations:^
// {
// _portraitToolsWrapperView.alpha = 1.0f;
// _landscapeToolsWrapperView.alpha = 1.0f;
//
// _portraitActionsView.alpha = 1.0f;
// _landscapeActionsView.alpha = 1.0f;
// } completion:^(__unused BOOL finished)
// {
// _portraitSettingsView.layer.shouldRasterize = false;
// _landscapeSettingsView.layer.shouldRasterize = false;
// }];
if (self.presentedForAvatarCreation) {
_drawingView.hidden = true;
}
- (void)transitionIn {
// if (self.presentedForAvatarCreation) {
// _drawingView.hidden = true;
// }
}
+ (CGRect)photoContainerFrameForParentViewFrame:(CGRect)parentViewFrame toolbarLandscapeSize:(CGFloat)toolbarLandscapeSize orientation:(UIInterfaceOrientation)orientation panelSize:(CGFloat)panelSize hasOnScreenNavigation:(bool)hasOnScreenNavigation
@ -558,7 +545,8 @@ const CGSize TGPhotoPaintingMaxSize = { 2560.0f, 2560.0f };
previewView.interactionEnded = nil;
[_interfaceController animateOut:^{
completion();
if (completion != nil)
completion();
}];
}

View File

@ -1322,9 +1322,7 @@
TGPhotoEditorBackButton backButtonType = TGPhotoEditorBackButtonCancel;
TGPhotoEditorDoneButton doneButtonType = TGPhotoEditorDoneButtonCheck;
if ([self presentedForSuggestedAvatar] && !_item.isVideo) {
[_portraitToolbarView setCancelDoneButtonsHidden:tab == TGPhotoEditorCropTab animated:!isInitialAppearance];
}
bool sideButtonsHiddenInCrop = [self presentedForSuggestedAvatar] && !_item.isVideo;
__weak TGPhotoEditorController *weakSelf = self;
TGPhotoEditorTabController *controller = nil;
@ -1339,6 +1337,8 @@
if ([self presentedForAvatarCreation])
{
[_containerView.superview insertSubview:_containerView belowSubview:_portraitToolbarView];
bool skipInitialTransition = (![self presentedFromCamera] && self.navigationController != nil) || self.skipInitialTransition;
TGPhotoAvatarPreviewController *cropController = [[TGPhotoAvatarPreviewController alloc] initWithContext:_context photoEditor:_photoEditor previewView:_previewView isForum:[self presentedForForumAvatarCreation] isSuggestion:[self presentedForSuggestedAvatar] isSuggesting:[self presentedForSuggestingAvatar] senderName:self.senderName];
@ -1487,6 +1487,15 @@
controller = cropController;
doneButtonType = TGPhotoEditorDoneButtonDone;
if (sideButtonsHiddenInCrop) {
[_portraitToolbarView setCancelDoneButtonsHidden:true animated:true];
[_portraitToolbarView setCenterButtonsHidden:false animated:true];
[_landscapeToolbarView setAllButtonsHidden:false animated:true];
} else {
[_portraitToolbarView setAllButtonsHidden:false animated:false];
[_landscapeToolbarView setAllButtonsHidden:false animated:false];
}
}
else
{
@ -1586,12 +1595,12 @@
case TGPhotoEditorPaintTab:
{
[_portraitToolbarView setAllButtonsHidden:true animated:false];
[_landscapeToolbarView setAllButtonsHidden:true animated:false];
[_portraitToolbarView setAllButtonsHidden:true animated:[self presentedForAvatarCreation]];
[_landscapeToolbarView setAllButtonsHidden:true animated:[self presentedForAvatarCreation]];
[_containerView.superview bringSubviewToFront:_containerView];
TGPhotoDrawingController *drawingController = [[TGPhotoDrawingController alloc] initWithContext:_context photoEditor:_photoEditor previewView:_previewView entitiesView:_fullEntitiesView stickersContext:_stickersContext];
TGPhotoDrawingController *drawingController = [[TGPhotoDrawingController alloc] initWithContext:_context photoEditor:_photoEditor previewView:_previewView entitiesView:_fullEntitiesView stickersContext:_stickersContext isAvatar:[self presentedForAvatarCreation]];
drawingController.requestDismiss = ^{
__strong TGPhotoEditorController *strongSelf = weakSelf;
if (strongSelf == nil)
@ -1602,7 +1611,11 @@
__strong TGPhotoEditorController *strongSelf = weakSelf;
if (strongSelf == nil)
return;
[strongSelf applyEditor];
if ([strongSelf presentedForAvatarCreation]) {
[strongSelf presentTab:TGPhotoEditorCropTab];
} else {
[strongSelf applyEditor];
}
};
drawingController.toolbarLandscapeSize = TGPhotoEditorToolbarSize;
drawingController.controlVideoPlayback = ^(bool play) {
@ -1657,6 +1670,10 @@
case TGPhotoEditorToolsTab:
{
if ([self presentedForSuggestedAvatar]) {
[_portraitToolbarView setCancelDoneButtonsHidden:false animated:true];
}
TGPhotoToolsController *toolsController = [[TGPhotoToolsController alloc] initWithContext:_context photoEditor:_photoEditor previewView:_previewView entitiesView:_fullEntitiesView];
toolsController.toolbarLandscapeSize = TGPhotoEditorToolbarSize;
toolsController.beginTransitionIn = ^UIView *(CGRect *referenceFrame, UIView **parentView, bool *noTransitionView)

View File

@ -544,6 +544,7 @@
_animatingCancelDoneButtons = hidden;
if (hidden) {
_cancelButton.modernHighlight = false;
_doneButton.modernHighlight = false;
}
_cancelButton.hidden = false;
_doneButton.hidden = false;
@ -561,6 +562,7 @@
if (hidden) {
_cancelButton.modernHighlight = true;
_doneButton.modernHighlight = true;
}
if (hidden) {
@ -578,6 +580,30 @@
}
}
- (void)setCenterButtonsHidden:(bool)hidden animated:(bool)animated
{
CGFloat targetAlpha = hidden ? 0.0f : 1.0f;
if (animated)
{
_buttonsWrapperView.hidden = false;
[UIView animateWithDuration:0.2f
animations:^
{
_buttonsWrapperView.alpha = targetAlpha;
} completion:^(__unused BOOL finished)
{
_buttonsWrapperView.hidden = hidden;
}];
}
else
{
_buttonsWrapperView.alpha = targetAlpha;
_buttonsWrapperView.hidden = hidden;
}
}
- (TGPhotoEditorButton *)buttonForTab:(TGPhotoEditorTab)tab
{
for (TGPhotoEditorButton *button in _buttonsWrapperView.subviews)

View File

@ -482,8 +482,8 @@ public final class LegacyPaintStickersContext: NSObject, TGPhotoPaintStickersCon
let contentWrapperView: UIView!
let interfaceController: TGPhotoDrawingInterfaceController!
init(context: AccountContext, size: CGSize, originalSize: CGSize) {
let interfaceController = DrawingScreen(context: context, size: size, originalSize: originalSize)
init(context: AccountContext, size: CGSize, originalSize: CGSize, isAvatar: Bool) {
let interfaceController = DrawingScreen(context: context, size: size, originalSize: originalSize, isAvatar: isAvatar)
self.interfaceController = interfaceController
self.drawingView = interfaceController.drawingView
self.drawingEntitiesView = interfaceController.entitiesView
@ -494,8 +494,8 @@ public final class LegacyPaintStickersContext: NSObject, TGPhotoPaintStickersCon
}
}
public func drawingAdapter(_ size: CGSize, originalSize: CGSize) -> TGPhotoDrawingAdapter! {
return LegacyDrawingAdapter(context: self.context, size: size, originalSize: originalSize)
public func drawingAdapter(_ size: CGSize, originalSize: CGSize, isAvatar: Bool) -> TGPhotoDrawingAdapter! {
return LegacyDrawingAdapter(context: self.context, size: size, originalSize: originalSize, isAvatar: isAvatar)
}
public func solidRoundedButton(_ title: String!, action: (() -> Void)!) -> (UIView & TGPhotoSolidRoundedButtonView)! {