mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-05 20:22:15 +00:00
52 lines
1.8 KiB
Swift
52 lines
1.8 KiB
Swift
//
|
|
// ImageCellNode.swift
|
|
// Sample
|
|
//
|
|
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under the BSD-style license found in the
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present,
|
|
// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
import UIKit
|
|
import AsyncDisplayKit
|
|
|
|
class ImageCellNode: ASCellNode {
|
|
let imageNode = ASImageNode()
|
|
required init(with image : UIImage) {
|
|
super.init()
|
|
imageNode.image = image
|
|
self.addSubnode(self.imageNode)
|
|
}
|
|
|
|
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
|
|
var imageRatio: CGFloat = 0.5
|
|
if imageNode.image != nil {
|
|
imageRatio = (imageNode.image?.size.height)! / (imageNode.image?.size.width)!
|
|
}
|
|
|
|
let imagePlace = ASRatioLayoutSpec(ratio: imageRatio, child: imageNode)
|
|
|
|
let stackLayout = ASStackLayoutSpec.horizontal()
|
|
stackLayout.justifyContent = .start
|
|
stackLayout.alignItems = .start
|
|
stackLayout.style.flexShrink = 1.0
|
|
stackLayout.children = [imagePlace]
|
|
|
|
return ASInsetLayoutSpec(insets: UIEdgeInsets.zero, child: stackLayout)
|
|
}
|
|
|
|
}
|