Cosmos icon indicating copy to clipboard operation
Cosmos copied to clipboard

Cosmos view size is incorrect in Right-to-left layout

Open evgenyneu opened this issue 6 years ago • 3 comments

Hi, Even RTL is working in design mode, But still if you add text to the view it will be damaged. Without Text: 2

With text: 1

Any solution? Thanks

Originally posted by @wajihkm in https://github.com/evgenyneu/Cosmos/issues/74#issuecomment-449928419

evgenyneu avatar Dec 27 '18 00:12 evgenyneu

Thanks for reporting the issue @wajihkm. I'm not sure I understood it. Are you saying that the margin between the cosmos view and the image is incorrect in RTL mode?

Assuming that this is the case, I created a demo app. It has a text and two labels to the right and left from the view (Fig. 1).

view_border_rtl_storyboard

Figure 1: A Cosmos view and two labels positioned to the left and the left form the view.

Then I ran the app in Right-to-left mode by clicking the menu item Product > Scheme > "Edit Scheme", and choosing "Right-to-left pseudolanguage ..." form Run > "Application Language" option. I've also added a red border to the view in order to see the view's size is calculated correctly. As far as I can see from Fig. 2, the views are positioned properly. The text labels do not overlap the cosmos view.

view_border_rtl_simulator

Figure 2: The app run in a simulator with Right-to-left language enabled.

We can also see from Fig. 2 that the red border surrounds both the stars and the text label "(1)", which means that the size of the view is calculated properly in the right-to-left mode.

It is possible that your app has different layout which causes this bug. I'm attaching the demo app below. Please let me know if it works for you.

UsingCosmos.zip

evgenyneu avatar Dec 27 '18 01:12 evgenyneu

Thanks for your fast reply @evgenyneu , I reattached a modified version of your code. I released that the problem is not 100% related to RTL. If you fixed the width of cosomoView in design then you changed cosmos's text during runtime, the stars will misplaced outer the red border. if you have RTL language the extra space will be occupied from the start of the cosmos view, otherwise the extra space will be occupied from the trailing. I hope you can understand me. Thanks UsingCosmos.zip

wajihkm avatar Dec 27 '18 06:12 wajihkm

Thanks for sending the demo. There is no need to use a width constraint on CosmosView, since its width is determined automatically based on the width of stars and text, similar to UILabel.

evgenyneu avatar Dec 28 '18 01:12 evgenyneu