How to set different row height which is dynamically loaded - titanium

Hi guys I have situation, where I am loading table rows dynamically. The code that set table row is like:
var rows = [];
_.each(records, function(rec) {
var row = Alloy.createController('myRow', rec).getView();
rows.push(row);
});
}
$.myaTable.setData(rows);
I have different value in each row. And I want to set row height to fit the texts. I tried to set the row height
"TableViewRow": {
height: Ti.UI.SIZE
}
I also changed the myRow.js like $.myRow.height = Ti.UI.SIZE.
But the problem - it is applying same height of to all rows. I show below in image:
Current Output:
My need is:
EDIT:
myRow.xml:
<TableViewRow id="ideaRow">
<View id="content">
<Label id="myTitle"></Label>
<Label id="myDesc"></Label>
<View id="control">
<View id="Control1" />
<View id="Control2" />
<View id="Control3" />
</View>
</View>
<TableViewRow>
myRow.js:
$. myTitle.text = args.title
$. myDesc.text = args.description
Do you think any solutions exists in Titanium for this. Thanks in advance

I can't reproduce your exact problem with 3.3.0.GA.
On iOS, the tableViewRows automatically fill up the whole screen without any TSS. This is because the Views inside your myRow.xml are set to Ti.UI.FILL by Titanium's default. The solution is to make sure you set height: Ti.UI.SIZE for your tags inside the myRow.xml

Related

Limiting column width in datagrid for command button columns

in React-Admin I want to limit the width of the columns that show edit, show buttons in the datagrid
I know I can use styles to set the width of other cells like TextFields, but cant find a way to do this with buttons
enter image description here
Inside Datagrid you can use the headerClassName cellClassName props to style both the cell in the header row and in body rows as described in the docs under section Datagrid/CSS-Api
<ShowButton
headerClassName={classes.hiddenOnSmallScreens}
cellClassName={classes.hiddenOnSmallScreens}
/>
*EDIT
Obviously this approach doesn't work when using typescript, probably a bug - you can work around it in this way:
const usePostListActionToolbarStyles = makeStyles({
toolbar: {
alignItems: "center",
display: "flex",
marginTop: -1,
marginBottom: -1
}
});
const PostListActionToolbar = ({ children, ...props }) => {
const classes = usePostListActionToolbarStyles();
return (
<div className={classes.toolbar}>
{Children.map(children, (button) => cloneElement(button, props))}
</div>
);
};
and then inside your Datagrid:
<Datagrid>
//...fields
<PostListActionToolbar>
<ShowButton/>
<EditButton/>
</PostListActionToolbar>
</Datagrid>

Is using conditional accessibility label text good?

I have this code in my React Native app that renders a list of types. Selected and not selected types have different backgrounds. Is it okay to make accessibility label text conditional?
<View style={styles.typesList}>
{types.map(type => {
return (
<TouchableOpacity
key={type}
style={[
styles.type,
{
backgroundColor: filterTypes.includes(type)
? Colors.white
: Colors.lightYellow
}
]}
onPress={() => {
handleFilterTypesChange(type);
}}
testID='type'
accessibilityLabel={`${
filterTypes.includes(type) ? 'Unselect' : 'Select'
} ${type} filter`}
>
<Text>{type}</Text>
</TouchableOpacity>
);
})}
</View>
The screen readers by default read-out if a checkbox is selected or not. So no need to put conditional text to just read out it. If you have multiple select boxes it is advised to use fieldsel and legend which will give details to visually challenged persons.
<fieldset>
<legend>Select your pizza toppings:</legend>
<input id="ham" type="checkbox" name="toppings" value="ham">
<label for="ham">Ham</label><br>
<input id="pepperoni" type="checkbox" name="toppings" value="pepperoni">
<label for="pepperoni">Pepperoni</label><br>
</fieldset>
The contains the group of checkboxes, and the labels the group. Screen readers may repeat the legend for each control in the group, so the legend text should be brief and descriptive.

Titanium scrollview

I have a question about scrollview for appcelerator titanium, I want to scroll labels inside scrollview:
scrollpage.xml
<View id="content" layout="vertical" top="100dp" width="100%">
<ScrollView contentWidth="Ti.UI.SIZE" contentHeight="Ti.UI.SIZE" top="10dp" id="svc" height="48dp" backgroundColor="#ff0000" >
</ScrollView>
</View>
</Window>
scrollpage.js
for ( i = 0; i < 19; i++) {
var scrollLabel = Ti.UI.createLabel({
width : Ti.UI.SIZE,
height : '40dp',
font : { fontSize : 14 },
color:'#000',
text : 'Portfolio'+i,
id:'label_'+i,
});
$.svc.add(scrollLabel);
}
The result
I tried ScrollableView but I want many items showing directly on screen.
My aim is to achieve this :
Please explain what did I do wrong! Thank you!
That's because by default the layout of a ScrollView is composite. So, if you want different layout, add layout="horizontal" on your ScrollableView to place your child element :
<ScrollView contentWidth="Ti.UI.SIZE" contentHeight="Ti.UI.SIZE" top="10dp" id="svc" height="48dp" backgroundColor="#ff0000" layout="horizontal"></ScrollView>
More information here about layout : http://docs.appcelerator.com/platform/latest/#!/guide/Layouts,_Positioning,_and_the_View_Hierarchy-section-29004895_Layouts,Positioning,andtheViewHierarchy-Layoutmodes

Minimum width/height in React Native

How can I set minimum width or height for React Native component?
In css, I can use min-width/min-height
https://facebook.github.io/react-native/docs/flexbox.html#content
There is no minWidth/minHeight on react-native docs
minHeight, maxHeight, minWidth and maxWidth properties are supported as of react-native version 0.29.0 for iOS and Android.
Here is the maxHeight description from react-native documentation. This description also applies for other min/max style properties.
maxHeight is the maximum height for this component, in
logical pixels.
It works similarly to max-height in CSS, but in React Native you must
use points or percentages. Ems and other units are not supported.
See https://developer.mozilla.org/en-US/docs/Web/CSS/max-height for
more details.
A dummy example:
<View
style={{
minWidth: '20%',
maxWidth: 500,
minHeight: '10%',
maxHeight: 150,
}}
/>
This answer is outdated now, use halilb's answer.
I solved this by using the onLayout prop, its very easy:
Example:
Step 1: I create a prop in our state that will be holding the current height of the image called curImgHeight.
constructor(){
super(props);
this.state={curImgHeight:0}
}
Step 2: Use the prop in any View or Element that supports the onLayout prop.
Here I use it with an Image. Then all we have to do is, change that state property whenever the actual image height is than our minimum height.
render(){
<Image
source={{uri: "https://placehold.it/350x150"}}
resizeMode='cover'
style={[styles.image, {height:(this.state.curImgHeight<=0?null:this.state.curImgHeight)}]}
onLayout={(e)=>{
let {height} = e.nativeEvent.layout;
let minimumImgHeight = 400; //We set the minimum height we want here.
if(height<= minimumImgHeight){ //Whenever the real height of the image is less than the minimum height
this.setState({curImgHeight:minimumImgHeight}); //just change the curImgHeight state property to the minimum height.
}
}}
/>
}
Thats how I solved it for me.
p.s: During my search I found that react-native unofficially supports minHeight and maxHeight but only for iOS and not for Android. I wouldn't dare using them though. The above code works well and gives me control.
I was able to work out the solution for you. Here's a working demo...
https://rnplay.org/apps/vaD1iA
And here are the key parts.
First, you pull in the device dimensions...
var Dimensions = require('Dimensions');
var {
width,
height
} = Dimensions.get('window');
Here's the button component, which uses the device width as the basis for the button's with
const Button = React.createClass({
render(){
return(
<TouchableHighlight>
<Text style={[styles.button,{width: width - 20}]}>
{this.props.children}
</Text>
</TouchableHighlight>
)
}
});
Then, as you can see here, the button width will be the same regardless of label content width.
You can use minHeight or flexBasis - it is similar.
You can do something like that:
_getButtonStyle() {
var style = {height:36,padding:8}
if(this.props.buttonText.length < 4){
style.width = 64
}
return style
}

Titanium TableView disappears when two TableViews are on same view

This is for a mobile app, running on the iPhone simulator, using SDK v 3.0.2 GA and the Alloy framework.
I have a window that has a tableview with an autocompleting search bar atop that table view. When the autocomplete begins to fire, it displays a tableview with the results below the search box, allowing a user to select from the results.
This all works fine, except that including the TableView on the search view causes the TableView on the original window to disappear.
The code is as follows:
myPlaces.xml
<Alloy>
<Window id="myDrawersWin">
<RightNavButton>
<Button id="showMyDrawers" title="Show Drawers" />
</RightNavButton>
<Require src="findPlace" id="findPlace"/>
<TableView id="placeListTable"/>
</Window>
</Alloy>
findPlace.xml
<Alloy>
<View id="searchContainer">
<TextField id="searchInput" hintText="Find a place..." />
</View>
<TableView id="searchResultsTable"/>
</Alloy>
findPlace.js
$.searchInput.addEventListener("change", function(){
if ($.searchInput.value.length > 2 && $.searchInput.value != "Find a place...") {
// do the search and get a response successfully
_.each(returnedVenues, function(venue){
tblData.push(Alloy.createController("venueSearchListItem", venue).getView());
});
$.searchResultsTable.setData(tblData);
$.searchResultsTable.visible = true;
},
onerror: function(e){
console.log("error");
console.log(e);
}
});
// invoke the HTTP client here
}
else {
$.searchResultsTable.visible = false;
}
});
findPlace.xml
"#searchContainer":{
width: "100%",
height: 50,
backgroundColor: "#B8D0DB",
top: 0
}
"#searchInput":{
width: "80%",
height: 30,
backgroundColor: "#FFFFFF"
}
"#searchResultsTable":{
width: "80%",
visible: false
}
If I take out the TableView in findPlace.xml, the original TableView on the window (placeListTable) shows up fine. If I add it back, it disappears. Also, if I move the TableView inside of <View id="searchContainer"> it will show up (but obviously, doesn't fit, due to the height restriction on searchContainer).
Any ideas? Is this a bug, or am I doing something stupid here?
Thanks for any help.
Justin
Found the solution to this problem, and as I suspected, it was stupidity.
The problem was that I'd set layout:vertical on the window stylesheet, meaning that the second TableView was displaying below the other one. Removing that solved the problem.