asyncdisplaykit


How can I enforce a minimum Height for a ASDisplayNode?


I've done quite a lot of work using AsyncDisplayKit until now and I'm really really happy with it. Unfortunately now I've hit a road block.
I can't get a ASButtonNode to have a minimum height (in a ASCellNode if this is important).
class SmallButtonCellNode: ASCellNode {
let normalSmallButton = ASButtonNode()
let selectedSmallButton = ASButtonNode()
init() {
super.init()
self.backgroundColor = UIColor.lightGrayColor()
// .. button title and background configuration here ..
let buttonSizeRange =
ASRelativeSizeRangeMake(
ASRelativeSizeMake(
ASRelativeDimensionMakeWithPercent(0),
ASRelativeDimensionMakeWithPoints(35.0)
),
ASRelativeSizeMake(
ASRelativeDimensionMakeWithPercent(1),
ASRelativeDimensionMakeWithPoints(35.0)
)
);
self.normalSmallButton.preferredFrameSize = CGSize(width: 111.0, height: 35.0)
self.normalSmallButton.flexGrow = true
self.normalSmallButton.sizeRange = buttonSizeRange
self.addSubnode(self.normalSmallButton)
self.selectedSmallButton.preferredFrameSize = CGSize(width: 111.0, height: 35.0)
self.selectedSmallButton.flexGrow = true
self.selectedSmallButton.sizeRange = buttonSizeRange
self.addSubnode(self.selectedSmallButton)
}
// MARK: - Layout
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec {
let spec =
ASStackLayoutSpec(
direction: .Horizontal,
spacing: 20.0,
justifyContent: .SpaceAround,
alignItems: .Center,
children: [self.normalSmallButton, self.selectedSmallButton]
)
return
ASInsetLayoutSpec(
insets: UIEdgeInsets(top: 20.0, left: 20.0, bottom: 20.0, right: 20.0),
child: spec
)
}
}
The result is (although the constrainedSize has a maximum of 100.0 in height):
The ASButtonNodes are only fitting the text height.
I've tried:
removing the preferred frame size (no effect)
change from .Center to .Stretch (the button is as tall as the cell - insets)
flexGrow = true in various places
I know that I could change the cell height from 100 to 75 using .Stretch and then the buttons will automatically end up being 35 pts tall but that's not what I want (because then the layout logic for "The button is 35 pts tall" will actually be part of the collection view delegate ..)
Please help :)
Updated answer:
Just went to asyncdisplaykit.org and saw a reference to ASStaticLayoutSpec. It should fix your problem. In layoutSpecThatFits() ...
spec.sizeRange = normalSmallButton.sizeRange
let staticSpec1 = ASStaticLayoutSpec(children: [spec])
return staticSpec1
....
If your cell is simple enough, I think that it would be easier and more straight-forward to just measure your subnodes in calculateSizeThatFits(constrainedSize: CGSize). Then in layout(), you calculate the .frame for each of your subnodes.
If you want to use layout specs, my hack would be to call .measure() on your subnodes in init(). Then in layoutSpecsThatFit, you can adjust your inset values to be the diff between the calculatedSize of your nodes and the minimum size. Good luck.
var diffY: CGFloat = (35.0 - selectedSmallButton.calculatedSize.height) / 2
if diffY < 0 { diffY = 0 }
return ASInsetLayoutSpec(
insets: UIEdgeInsets(top: diffY,
left: 20.0,
bottom: diffY,
right: 20.0),
child: spec)

Related Links

How can I enforce a minimum Height for a ASDisplayNode?
AsyncDisplayKit Layout - how to enforce a maximum height (or width)

Categories

HOME
porting
apache-flink
nvd3.js
depth
themes
serialization
solaris
can
telegram-bot
jetty
x264
vsm
android-json
google-cloud-datalab
odoo-8
nstableheaderview
fhir
x-cart
comsol
enterprise-architect
job-scheduling
mvc-mini-profiler
firefox-addon
forgot-password
template-engine
google-container-registry
pyramid
microsoft-ocr
undertow
imagemap
php-mysqlidb
mongoid6
scriptella
zxing
beautifier
custom-post-type
fable-f#
intersystems-cache
tizen-tv
constexpr
scrollview
xbox
erb
clickjacking
github3.py
swagger-php
parse-tree
node-mssql
gdata
typesafe-config
apache-stanbol
magento-1.9.3
install.packages
wc
yii2-api
activeperl
yii2-user
java-6
colorbar
gpg-signature
cd-burning
donations
smartfoxserver
autosar
tinkerpop3
flex4.6
tooleap
dimension
xdoclet
lean
deep
bizagi
upx
contentcontrol
opl
sciruby
computer-architecture
vigenere
binomial-theorem
dock
lasso
vacuum
sha512
liquid-layout
typeconverter
pseudo-class
crowd
administration
device-tree
human-computer-interface
square-bracket
isqlquery
actiondispatch
android-icons
fb.ui
wcf-configuration
rmiregistry
boost-signals
thttpd
ilasm
infobright
uipagecontrol
codebase
socketserver
vs-android
nstokenfield
alsb

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App