Image disappears on setting width [Titanium] - image

I created an imageView in Titanium. Whenever I set the width and height of the image to "auto"; the image is not visible. But if I manually set height and width of the image, the image appears.
Why does this happen ?
var image = Titanium.UI.createImageView({
backgroundImage:'test.png',
width: 'auto',
height: 'auto'
})

If you go here on the DOCs you will see that `auto is deprecated:
'auto' represents the default sizing behavior for a given type of view. The use of 'auto' is deprecated, and should be replaced with the SIZE or FILL constants if it is necessary to set the view's behavior explicitly.
Instead try setting the width and height to Titanium.UI.SIZE, Titanium.UI.FILL, a pixel value, or a percentage of the parent view.

Related

Automatically size image components in React Native

I want to set the width of an Image component to be 100% of my container's width and the height to be set according to the result width value and image's aspect ratio.
My container has some padding, which means that Dimensions.get('window').width is not useful to me since it does not gives me the value that results from image's width being set to 100%. Other scenarios also can't afford the Dimensions API as a acceptable solution.
Here's an code example:
<View
style={{
flex: 1,
paddingHorizontal: 20,
}}>
<Image
style={{
flex: 1, // Not what I want => just so I can see the image
width: '100%',
// height: 'auto', // The behavior that I want
backgroundColor: 'red',
}}
resizeMode={'contain'}
source={{
uri: 'https://via.placeholder.com/200x400/000000',
}}
/>
</View>
Result:
The red background serves just to visualize that the Image component.
Using onLayout prop I can get the runtime value of the resulting width, and with the aid of the Image API i could calculate the desired height. The problem with that is that React Native will first render a 0 height component and just after that onLayout seems to be resolved, and that makes sense.
So?
Is there a way to get before hand the width value of a image component such as this (declared using relative width)?
Is automatically setting image height even possible in React Native? If so, how?
Notes:
- In the image docs of React Native there is an explanation of why they chose not to size image components automatically by default.
- At least in this case, Parent onLayout is resolved after its children.
In your componentDidMount you could calculate the image metrics, and then use that height and width to calculate the aspectRatio.
componentDidMount = () => {
Image.getSize(YourUri, (width, height) => {
this.setState({width, height});
});
}
In your image you will add the styles like this:
<Image
style={{
width: '100%',
backgroundColor: 'red',
aspectRatio: this.state.height !== null ? this.state.width / this.state.height : 1
}}
resizeMode={'contain'}
source={{
uri: 'https://via.placeholder.com/200x400/000000',
}}
/>
As stated in React native docs:
Aspect ratio controls the size of the undefined dimension of a node.
Aspect ratio is a non-standard property only available in React Native
and not CSS.
-On a node with a set width/height aspect ratio controls the size of the unset dimension
-On a node with a set flex basis aspect ratio controls the size of the node in the cross axis if unset
-On a node with a measure function aspect ratio works as though the measure function measures the flex basis
-On a node with flex grow/shrink aspect ratio controls the size of the node in the cross axis if unset
Aspect ratio takes min/max dimensions into account

How do I make an image its actual size up to a certain point in a window? Extjs 6 classic

I want to have a window xtype that contains just an of its own size but when I show my window, it shows up as a tiny square in the middle of the screen (not the actual size of the image). I've tried using this block of code
listeners:{
afterrender: function(me){
me.el.on({
load: function (evt, ele, eOpts){
me.updateLayout();
},
error: function(evt,ele,eOpts){
}
});
}
}
to update the layout of the parent window from within the image xtype, but this makes the window not centered and centering the window during an afterrender event isn't working. Am I missing something simple? I also have the maxWidth and maxHeight configs of the image set to Ext.getBody().getViewSize().width and height respectively.
Sencha had a good reason not to use xtype: 'image' for their own icons etc.
xtype: 'image' only works with fixed width and height, so you can't even preserve aspect ratio, as far as I know.
What you want to do is to have a container and set the background-image of the container.
xtype: 'container',
style: 'background-image: url(\'image.jpg\'); background-repeat:no-repeat; background-position:50% 50%; background-size:contain'
or even just use the window: https://fiddle.sencha.com/#view/editor&fiddle/244n

Height issue with ckeditor

I am using ckeditor and I have set the textarea size correctly via code:
CKEDITOR.replace( 'editor1', {
width: 468,
height: 132
} );
I have also deactivated the resizing correctly with code:
config.resize_enabled = false;
My problem is that the textarea's height still allows for text to be typed and the textarea expands vertically. I want the textarea to be set via a certain height and not move past that. So no more text can be entered once the height has been met.

Appcelerator Titanium - How do I place an image at the bottom of the screen

I have a main view, then on that view I have, as children, two labels and an image. I want the labels to flow one after another from the top of the screen and I want the image at the bottom. I get the labels to flow properly by setting layout:'vertical' in the main window. But once that is done, I can't seem to force the image to the bottom. Here is a snippet of my code:
var self = Ti.UI.createView({
backgroundColor:'#fff',
layout:'vertical'
});
var l1 = Titanium.UI.createLabel({
text:quote,
color:'#000',
shadowColor:'#ddd',
shadowOffset:{x:2,y:2},
font:{fontFamily:'Marker Felt',fontSize:24},
top:20,
left:15,
right:15,
height:'auto'
});
self.add(l1);
var l2 = Titanium.UI.createLabel({
text:author,
color:'#000',
shadowColor:'#ddd',
shadowOffset:{x:2,y:2},
font:{fontSize:16},
top:10,
left:15,
right:15,
height:'auto',
textAlign:'right'
});
self.add(l2);
var imgView = Titanium.UI.createImageView({
image:myimage,
setBottom:10,
height:100
});
self.add(imgView);
I have tried setting the image layout and that doesn't work. If I change the 'self' window layout to 'absolute' then I can't seem to get the labels to flow cleanly after one another. The first label is of variable height so I need them to follow each other.
I am using Titanium 1.82.
Thanks. In advance.
You might need to add another view. The 'base' view would have what you are calling 'self' added at top:0 and height: 'auto'
Then add imgView to 'base' with bottom: 10 (not setBottom like you have).
Just set the bottom:0; position: fixed; i think this will help u to set the image bottom of the screen.. If it still not working means try with Html,Css and Javascript for design it will be very easy.

how to add scrollbars to jqgrid view window and restrict its height

If table contains big multi-line text column, pressing jqgrid view toolbar button creates view window
with big height and without scrollbar. Most of data is outside screen and is not visible.
I tried to add scrollbars and restrict its height using
jQuery.extend(jQuery.jgrid.view, {
savekey: [true, 13],
recreateForm: true,
closeOnEscape: true,
dataheight: screen.height-230,
height: 0.82* screen.height,
width: 0.96*screen.width,
top:5
});
but those settings are ignored ( they work for edit window only if jQuery.jgrid.edit is used).
How to add scrollbar(s) and retrict view window height if it contains more data than fits to screen ?
I suggest to get the demo from the answer and extend the code a little. In the method beforeShowForm I suggest to include additional line
$(this).children("span").css({
overflow: "auto",
"text-align": "inherit", // overwrite 'text-align: "right"' if exist
display: "inline-block",
"max-height": "100px"
});
You can see the results on the demo. The height of the View form will be variable, but the maximal height of every field will be restricted to 100px (see max-height above):
or

Resources