Bug 26169 - Inappropriate layouts with Forms (iOS) with custom view renderers with child views and constraints.
Summary: Inappropriate layouts with Forms (iOS) with custom view renderers with child ...
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-01-19 12:54 UTC by Brian Berry
Modified: 2017-06-19 13:51 UTC (History)
5 users (show)

Tags: ngf
Is this bug a regression?: ---
Last known good build:

Native and Forms implementations for comparison. (4.08 MB, application/x-gzip)
2015-01-19 12:54 UTC, Brian Berry

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Brian Berry 2015-01-19 12:54:12 UTC
Created attachment 9401 [details]
Native and Forms implementations for comparison.

Found: Inappropriate layouts with Forms when a custom view
renderer has child views with constraints.

Steps to reproduce:
  * Extract the attached tarball.
  * Load the "Native" project, build, deploy, run.
  * Observe and note the expected "good" behavior,
    a blue rectangle inset in a red background that
    retains the same border size on device rotation.
  * Load the "Forms" project, build, deploy run.
    NOTE! *** Run on an iPad Mini. ***  Use a
    retina mini if able, as it is what I have and
    it may be relevant to reproducibility.
  * Observe and note that the initial layout is
    correct and identical to the "Native" run
    previously, but fails to retain the proper
    layout upon device rotation to an orientation
    with a different aspect ratio than that which
    the app started with.

Expected: Proper layout in all cases.

Additional notes:

Both projects (native, forms) attempt to construct the
same basic setup within their respective patterns:
  * An outer view, screen-sized, red background.
  * An inner view, inset 32 points, green background.
  * The inner view clips to bounds and contains a
    blue child view that is, through contraints,
    both centered and fixed size (2048 points here).
  * Given this arrangement, you expect to never see
    green---the large/centered blue will be all that is
    visible (though inset in red due to the clipping).

The native case (constructed in AppDelegate.cs) is
a simple hierarchy of UIViews, where standard
constraints are used both to inset the inner within
the outer by 32 points and then constrain the large
view (centered, fixed size) within the inner.

The Forms case (again, see its AppDelegate.cs) employs
a Forms RelativeLayout to accomplish the 32-point
inset behavior.  The inner view, however, is
implemented with a custom view renderer.  Within
this custom view renderer, the inner view (green)
has the same "large" (blue) native view added with
the same centering / sizing constraints as in the
native project case.  On my retina Mini iPad:

  -> As authored, the layout does not remain correct
     except in orientations with the same aspect ratio
     as when the app started on the device.

  -> If you *do not add* the large view to inner,
     running results in the expected, proper outcome
     of the green view inset within red and correct
     across device rotations.

My expectation here is that, when using a custom
view renderer on iOS, from the POV of Forms, should
be a black box. That is to say, the Inner-assigned
native view (set via SetNativeControl) should see
proper layout by the Forms implementation regardless
of what that native view might have under the hood.
Instead, what I appear to see is some kind of
encapsulation violation where Forms either inspects
or somehow is affected by the should-be-independent
content within.

NOTE: When I run the Forms example on my iPhone 6, I
actually get the proper behavior, which is curious.
The issue appears to be idiom-dependent or...other?
Comment 1 asimk 2015-01-20 13:07:43 UTC
I have checked this issue with the help of sample app attached in bug
description and getting the same behavior. I observed that when I run "Native" App its working fine on rotation of device. But on running "Forms" App on iPAD mini(iOS 8.0.2) and I am not getting proper layout on rotation of device(in landscape mode).

Note: I able to reproduce this issue on iPAD mini but on iPhone 6 it is working fine. 

Screencast: http://www.screencast.com/t/6LletlpO4
Device Log: https://gist.github.com/Udham1/82ceb6706980261193a9
Ide Log: https://gist.github.com/Udham1/e9726baac3c11321f8ee

Environment Info:
=== Xamarin Studio ===

Version 5.7.1 (build 13)
Installation UUID: ce927b2a-2c07-44c5-b186-09cfdafba6dc
 Mono 3.12.0 ((detached/a813491)
 GTK+ 2.24.23 (Raleigh theme)

 Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: d8e6436
Build date: 2015-01-18 17:38:20-0500

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/xamarin76/Desktop/android-sdk-macosx
 Supported Android versions:
  1.6    (API level 4)
  2.1    (API level 7)
  2.2    (API level 8)
  2.3    (API level 10)
  3.1    (API level 12)
  4.0    (API level 14)
  4.0.3  (API level 15)
  4.1    (API level 16)
  4.2    (API level 17)
  4.3    (API level 18)
  4.4    (API level 19)
  4.4.87 (API level 20)
  5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Build Information ===

Release ID: 507010013
Git revision: 8e357d6be321e716f361ebc9591e4cee7f217c21
Build date: 2015-01-15 14:23:22-05
Xamarin addins: a6842a7727f64e956f942b8160f7835c9d9076a4

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin76s-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64