Bug 60060 - Almost all time cannot show more for Xamarin Today widget on iOS 11
Summary: Almost all time cannot show more for Xamarin Today widget on iOS 11
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: unspecified
Hardware: PC Windows
: --- critical
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL: https://stackoverflow.com/questions/4...
Depends on:
Blocks:
 
Reported: 2017-10-09 16:26 UTC by Dzmitry Sharkou
Modified: 2017-10-09 17:26 UTC (History)
3 users (show)

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

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:
Status:
RESOLVED INVALID

Description Dzmitry Sharkou 2017-10-09 16:26:33 UTC
# Steps to reproduce
Add today widget on iPhone iOS 11.


# Expected behavior
Today Widget should increase height for widget and WidgetPerformUpdate method should always called after changing PreferredContentSize.

# Actual behavior
Today Widget not changed height for widget.

# Supplemental info (logs, images, videos)
I have today widget and sometimes "show more" is not working. This issue appears only in iOS 11, previous versions (8, 9, 10) worked well. I don't understand what I'm doing wrong and why I cannot make widget expanded. I've investigate this issue and found that "WidgetPerformUpdate" was not triggered after change "PreferredContentSize" inside "WidgetActiveDisplayModeDidChange" and this is beacause "View.Bounds" of widget not changed after changing "PreferredContentSize".

# Test environment (full version information)
Any iPhone(6s,7,8) with iOS 11.

Here is my sample of code:
```csharp
[Register ("TodayViewController")]
public class TodayViewController : UIViewController, INCWidgetProviding
{
    private const int PrefferedHeight = 300;

    private readonly ISettings _settings;

    public TodayViewController(IntPtr handle) : base (handle)
    {
        _settings = AppContainer.Resolve<ISettings>();
    }

    static TodayViewController()
    {
        AppContainer.Container = (new iOSAppSetup()).CreateContainer();
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        AddOpenApplicationEvent();

        // Tell widget it can be expanded
                ExtensionContext.SetWidgetLargestAvailableDisplayMode(NCWidgetDisplayMode.Expanded);

        // Get the maximum size
        var maxSize = ExtensionContext.GetWidgetMaximumSize(NCWidgetDisplayMode.Expanded);
        PreferredContentSize = new CGSize(maxSize.Width, PrefferedHeight);

        View.AddSubview(***view according to maxSize***);
    }

    private void AddOpenApplicationEvent()
    {
        var tapWidget = new UITapGestureRecognizer();
        tapWidget.AddTarget(() =>
        {
            UIApplication.SharedApplication.OpenUrl(new NSUrl("test://"));
        });

        View.AddGestureRecognizer(tapWidget);
    }

    [Export("widgetPerformUpdateWithCompletionHandler:")]
    public void WidgetPerformUpdate(Action<NCUpdateResult> completionHandler)
    {
        UpdateWidget();

        switch (ExtensionContext.GetWidgetActiveDisplayMode())
        {
            case NCWidgetDisplayMode.Compact:
                // changes according to compact mode
                break;
            case NCWidgetDisplayMode.Expanded:
                // changes according to expanded mode
                break;
        }

        completionHandler(NCUpdateResult.NewData);
    }

    [Export("widgetActiveDisplayModeDidChange:withMaximumSize:")]
    public void WidgetActiveDisplayModeDidChange(NCWidgetDisplayMode activeDisplayMode, CGSize maxSize)
    {
        // Take action based on the display mode
        switch (activeDisplayMode)
        {
            case NCWidgetDisplayMode.Compact:
                PreferredContentSize = maxSize;
                // changes according to compact mode
                break;
            case NCWidgetDisplayMode.Expanded:
                PreferredContentSize = new CGSize(maxSize.Width, PrefferedHeight);
                // changes according to expanded mode
                break;
        }
    }

    private void UpdateWidget()
    {
        // some updates
    }
}
```
Comment 1 Alex Soto [MSFT] 2017-10-09 17:22:03 UTC
The broader developer community would be the best and quickest place for additional troubleshooting help on this issue.
Posting a question on Stack Overflow [0] (which I see you did :D) or the Xamarin Forums [1][2] would be the best next step.

[0] https://stackoverflow.com/questions/tagged/xamarin
[1] https://forums.xamarin.com/categories/ios
[2] https://forums.xamarin.com/categories/mac

(Investigation by the Xamarin team in the bug tracker for an issue like this would usually require that the reporter include additional background info like a complete project test case in C# and Obj-C to hint that Xamarin is behaving differently compared to Xcode.)

In case it might also be a helpful reference, you can find some general recommendations on the best places to ask various kinds of questions about Xamarin on:

https://developer.xamarin.com/guides/cross-platform/troubleshooting/support-options/
Comment 2 Dzmitry Sharkou 2017-10-09 17:26:03 UTC
Thanks! I don't understand is this bug in Xamarin.iOS or in iOS platform directly. So I've posted it here and to stackoverflow. I hope somebody can help me.