Wrapping text around an image with React-Native - word-wrap

I try to create a View with an Image and a Text component that wraps around the Image component.
My styling:
textContainer: {
flexDirection: 'row',
},
text: {
flex: 10,
},
image: {
flex:1,
height: 180,
width: 150,
margin: 10,
borderColor: '#ccc',
borderWidth: 1,
}
My component:
<ScrollView style={styles.contentContainer} >
{this.props.content.title_1 ? <Text style={styles.title}>{this.props.content.title_1}</Text> : null}
<View style={styles.textContainer}>
{this.props.content.text_1 ? <Text style={styles.text}>{this.props.content.text_1}</Text> : null}
{this.props.content.image_1 ? <Image width={null} height={null} style={styles.image} source={this.props.content.image_1} /> : null}
</View>
</ScrollView>
This is what the result: (not wrapping at all haha)
In the image beneath here, I quickly hacked the little image into the text. But I can't get the text to be wrapped around..
I hope anyone can help me in the right direction!

This is really hard but there is one weird way to do this.. Try the following. It worked for me but place I am doing this is too deep in the other views.:
<Text>
<View style={{width:400, height:100, flex:1, flexDirection:'row'}}>
<Image source={require('')}/>
<Text>Your Content Here</Text>
</View>
</Text>
Good luck. Please put a comment letting us know if it worked.

On android you cannot place a View inside Text, but you can place an Image, here is an example:
<Text>
<Image source="" />
<Text> Insert your text here </Text>
</Text>

Although this is an old post, I'll add this because I have recently had this problem and found a totally different approach that works for me. I don't have the code to hand (I can get it if anyone wants it), but the principle was this:
Requirement: to have a picture in the top left corner of the screen that takes up about half the screen width, with text starting to the right of it and then continuing beneath it for the whole width of the screen.
In XML, create a RelativeLayout containing an ImageView (IV) on the left and a TextView (TVA), set to wrap content, on the right. Then create another TextView (TVB) to sit below the Relative Layout. TVA is for the text beside the image and TVB for the text beneath it.
Put your image in IV. Then measure the height of IV in pixels (dpi). Call this height IVh
Put some of your text in TVA. As long as there is enough text to wrap over several lines, it doesn't really matter how much. Then measure the height of TVA in pixels. Call this height TVh
Compare IVh with TVh. If IVh=TVh then you have just the right amount of text to sit alongside your image. If TVh = IVh x 2 then you have twice as much text as you should have. And so on.
Adjust the number of words accordingly and put the right number into TVA, replacing what was there, then put the rest of the text in TVB.
You will need to play with margins and padding to allow an adequate margin around the image. Also, in steps 3 and 4 after you have put your image into ImageView or your text into TextView, you will need a delay before measuring the heights, to allow the display to be created - otherwise the measurement will be done too soon, before there is anything on the screen, and will return a height of zero. I found 200 milliseconds quite adequate and it's too fast for the user to notice a delay.

Related

Ensure amCharts bubble chart area is square

When creating a bubble chart, such as https://www.amcharts.com/demos/bubble-chart/, is it possible to ensure the chart area/grid is square without specifying the chart div width and height? I'm hoping it could be somewhat responsive. No matter what the window size, the chart 's grid is square. It would need to take into consideration any axis labels.
I'm using React/TypeScript. Thanks!
After struggling with amchart settings to no avail, the following solution works. However, seems like there should be away to do in with chart settings.
This article explains how to maintain a specific aspect ratio for images. I simply adopted it for the bubble chart.
<div style={{ position: 'relative', paddingTop: '93%' }}>
<div id={chartId} style={{ position: 'absolute', top: 0, left: 0, height: '100%', width: '100%' }}></div>
</div>
Create a container div with relative positioning and the top padding to the correct aspect ratio
Create the chart div as a child with absolute positioning
Render the page
Take a screenshot, paste it in your favorite image editor
Measure the pixels
Recalculate the top padding
For my chart, which has axis text on the left and bottom, 93% was perfect. Now, no matter the page width or device, the grid is always square. HTH.

What properties it is necessary to set view1, so that it fills the rest of the window?

What properties it is necessary to set view1, so that it fills the rest of the window?
<Alloy>
<Window>
<View id="view1">
</View>
<View id="view2" height="50">
</View>
</Window>
</Alloy>
<Alloy>
<Window>
<View id="view1" top="0" bottom="50" width="100%">
</View>
<View id="view2" height="50" bottom="0" width="100%">
</View>
</Window>
</Alloy>
Also it is good to put the dimensions in the style (TSS) file instead of putting them in the view XML file. If this resolves your query then mark it as an answer for the reference for the rest of the community.
There are multiple ways to fill dimensions. It depends on what kind of layout type you have used like - vertical, horizontal or composite (default).
Vertical
Aligns children below each other.
You can control width, left, right, top & bottom properties. (bottom property doesn't work for last child)
Last child can occupy rest of the vertical height of parent.
Horizontal:
Aligns children from left-to-right in horizontal plane.
Can control left, right, top & bottom properties (right property doesn't work for last child).
Last child can occupy remaining width of view
Composite or default
Most flexible if you have not oriented UI.
Can keep views anywhere using top,left,right,bottom.
Assigning left & right only will define the width. Adding width with left & right will obey width keeping left & right restrictions.
-- e.g. if left & right = 20 & width=Ti.UI.SIZE, then view will start from left & will have width as Ti.UI.SIZE & will not go beyond right=20
Same rule as above applies for height as well.

React Native Maintaining aspect ratio image ios

I have a 1242 X 450 image, which I’d like to display on a 1x 2x and 3x devices. The current code, which I have, works fine for 3x devices but I see that the edge of the image gets cropped on a 2x device and possible on a 1x device too.
In code I am setting width to 414 and height to 150 (because 1242 X 450 /3x)
Is there any way I can fix it?
The image is inside a list view
<View style={styles.row}>
<Image
style={styles.featureImage}
source={{
uri: this.props.image_src
}}/>
</View>
const styles = StyleSheet.create({
row: {
alignItems: 'center',
backgroundColor: 'lightgrey',
flexDirection: 'row',
margin: 6,
},
featureImage: {
height: 150,
width: 414
}
});
You don't need to deal with image's size. You just give width and height property properly.
import Platform and get width and height of device.https://facebook.github.io/react-native/docs/dimensions.html
var {scrHeight, scrwidth} = Dimensions.get('window');
define an image container style
imageContainer = {
width:scrwidth/5,
height:scrHeight/5,
}
define image style and use resizeMode for image
resizeMode enum('cover', 'contain', 'stretch', 'repeat', 'center')
imageStyle={
flex:1,
}
<View style={styles.imageContainer }>
<Image style={styles.imageStyle} resizeMode={'contain'}>
</Image>
</View>
No matter how big the image is it will cover screenWidth/5 X screenHeight/5.
If your image has high resolution and device is not the image will be compressed in the contrary case it will be stretched. Both case especially second one if there is a big difference between image resolution and area which is left for image you will have bad image vision in your app. To avoid this situation you can add different sizes of the same image.
add
└── img
├── apple#1x.png 100x100 (resolutions are random)
└── apple#2x.png 150x150
apple#3x.png 175x175
https://facebook.github.io/react-native/docs/images.html
If you do so proper image will be chosen by react automatically. Images are chosen according to dpi of device. If your device has nice resolution you get bigger image if not so smaller image. This situation mostly works except devices having big sizes and low resolutions( some android tablets). In this case according to dpi image will be probably smallest image so there will be a bad quality.

How to get width/height of displayed image in javafx imageView?

I need to get width/height of displayed image in imegView and compare it to orginal image size which is in imageView.getImage().getWidth()/getHeight() and listen changes if user resize it form application GUI.
I get this size from imageView.fitWidthProperty() and similar for height, but I get size of imageView not image within it:
I get size of blue which is imageView but I need size of displayed image (green). How can I get it as property to listen when user resize window app (green also change size but it seems to have max and min size so it stop resize with imageView when it is max or min).
I use this property to compute % of size of orginal image in bottom right below blue rectangle.
Is it possible?
E: Below is fxml of this tab:
<BorderPane fx:id="root" fx:controller="..."
xmlns:fx="..." xmlns="..." stylesheets="#...css">
<center>
<StackPane>
<ImageView fx:id="..."/>
<fx:include source="...fxml" fx:id="..."/>
</StackPane>
</center>
<bottom>
<VBox fx:id="..." minHeight="110" styleClass="small-padding" spacing="5">
<HBox alignment="CENTER_RIGHT" spacing="5">
<fx:include source="...fxml" resources="..."
fx:id="..."/>
</HBox>
<TextArea fx:id="..." promptText="%..." styleClass="-fx-description-text-area"/>
</VBox>
</bottom>
When the ImageView is set to preserve the aspect ratio, one has to calculate the real dimensions by hand. At least I've not found another way.
double aspectRatio = image.getWidth() / image.getHeight();
double realWidth = Math.min(imageView.getFitWidth(), imageView.getFitHeight() * aspectRatio);
double realHeight = Math.min(imageView.getFitHeight(), imageView.getFitWidth() / aspectRatio);
To explain this a bit: getFitHeight/Width is your blue rectangle. When preserving the aspect ratio of the source image, at least one side of the blue rectangle must have the same length as the corresponding side of the green rectangle. Also, the green rectangle will always be inside of the blue one, hence the call to Math.min().
~>1)
The fact that the Image is not resizing to cover all the ImageView has to do with preserveRatio method.If you want to be covered setPreserveRatio(false);
with a combination of setSmooth( true );
~>2)
The green border is the size of the original image.
~>3)
Before adding the Image to the ImageView you can do:
Image image = new Image("FILE:...");
image.getWidth( );
image.getHeight( );
And that is the original size of the image.
As for the size of the image when it is displayed inside the ImageView:
imageView.getFitWidth();
imageView.getFitHeight();
For the size of ImageView inside the Scene (the blue border in your question):
imageView.getWidth();
imageView.getHeight();
ImageView class has properties for the above.
I am not aware of any property that you could use directly to get at the numbers you want but you might propose this as an improvement for a future version of JavaFX.
What you can do now is write some code which tracks all proerties of the ImageView which have an influence on the size of the displayed image and then compute the displayed size yourself. This does not sound too complicated to me.

How to show images with keeping their proportion in mvc3?

In mvc3 Products have more images and there is standard box size that all images seems in that in view.
Users enter images in different sizes: 200x800, 2200x500 ..etc. But I must show all images in standard box in 150x120 sizes. Most images stretchs horizontal or vertical in 150x120 size box and seems very bad.
<img src="#Url.Content( Path.Combine( "~/Uploads/Products/", #item.Date.Value.ToShortDateString(), #item.ImagePath1 ) )" width="150" height="120" alt="" />
How can I do all images get small, but to keep proportion ?
one way to keep propotions is to set the width value in css, but then the image will have the width and the height is unknown depending och the startimage. This will be the simplest way to fix the streched images. But you will not know the height as mentioned.
And ofc you must load the big image (big transfer size), so this may not be a propriate solution.
razor code
<img src="#Url.Content( Path.Combine( "~/Uploads/Products/", item.Date.Value.ToShortDateString(), #item.ImagePath1 ) )" alt="" />
css code
.parentDiv img{
width: 150px;
}
You got good question. However one way to do this is to ask user to upload in some proportion using javascript.
E.g your input control should be like
<input id="ImageFile" name="ImageFile" type="file" onchange="check_filesize(this.value,'upload');" />
And in javascript your can check file size and etc.
Another is to make use of ImageResizeClass and in your Upload Control you can resize the file to match your expectation size to shown in div.
So your upload controller would be something like following...
public ActionResult Upload(Image image, HttpPostedFileBase ImageFile)
{
ResizeImageHelper resizeImageHelper = new ResizeImageHelper();
resizeImageHelper.ResizeImage(path + ImageFile.FileName, path + ImageFile.FileName, 640, 480, false);
resizeImageHelper.ResizeImage(path + ImageFile.FileName, path + "thumb" + ImageFile.FileName, 74, 74, false);
image.imageLocation = ImageFile.FileName;
image.imageThumb = "thumb" + ImageFile.FileName;
imageRepository.Add(image);
imageRepository.Save();
}
This way you can make sure to show the image perfectly.
Hope you understand and this helps.

Resources