/
FlyoutNavigationController.cs
822 lines (729 loc) · 21.4 KB
/
FlyoutNavigationController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
// Copyright 2011 Clancey
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Diagnostics;
#if __UNIFIED__
using CoreGraphics;
using Foundation;
using ObjCRuntime;
using UIKit;
#else
using System.Drawing;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;
using CGRect=System.Drawing.RectangleF;
using CGSize=System.Drawing.SizeF;
using CGPoint=System.Drawing.PointF;
#endif
using MonoTouch.Dialog;
namespace FlyoutNavigation
{
public enum FlyOutNavigationPosition {
Left = 0, // default
Right
};
[Register("FlyoutNavigationController")]
public class FlyoutNavigationController : UIViewController
{
const float sidebarFlickVelocity = 1000.0f;
public const int menuWidth = 280;
//public UISearchBar SearchBar;
UIButton closeButton;
bool firstLaunch = true;
FlyOutNavigationPosition position;
DialogViewController navigation;
public DialogViewController NavigationViewController
{
get { return navigation; }
}
protected UIView menuBorder;
protected UIColor menuBorderColor = UIColor.LightGray;
public UIColor MenuBorderColor
{
get { return menuBorderColor; }
set { menuBorderColor = value;
if (menuBorder != null)
{
menuBorder.BackgroundColor = menuBorderColor;
menuBorder.SetNeedsDisplay();
}
}
}
protected bool showMenuBorder = false;
public bool ShowMenuBorder
{
get { return showMenuBorder; }
set { showMenuBorder = value; }
}
int selectedIndex;
UIView shadowView;
#if __UNIFIED__
nfloat startX;
#else
float startX;
#endif
UIColor tintColor;
protected UIViewController[] viewControllers;
bool hideShadow;
public FlyoutNavigationController(IntPtr handle) : base(handle)
{
Initialize();
}
public FlyoutNavigationController(UITableViewStyle navigationStyle = UITableViewStyle.Plain)
{
Initialize(navigationStyle);
}
public UIColor TintColor
{
get { return tintColor; }
set
{
if (tintColor == value)
return;
//SearchBar.TintColor = value;
}
}
public FlyOutNavigationPosition Position {
get {
return position;
}
set {
position = value;
shadowView.Layer.ShadowOffset = new CGSize(Position == FlyOutNavigationPosition.Left ? -5 : 5, -1);
if (openGesture != null)
openGesture.Edges = position == FlyOutNavigationPosition.Left ? UIRectEdge.Left : UIRectEdge.Right;
}
}
public Action SelectedIndexChanged { get; set; }
public bool AlwaysShowLandscapeMenu { get; set; }
public bool ForceMenuOpen { get; set; }
private bool AlreadyLayedOut = false;
public bool NavigationOpenedByLandscapeRotation { get; private set; }
public bool HideShadow
{
get { return hideShadow; }
set
{
if (value == hideShadow)
return;
hideShadow = value;
if (hideShadow) {
if (mainView != null)
View.InsertSubviewBelow (shadowView, mainView);
} else {
shadowView.RemoveFromSuperview ();
}
}
}
public UIColor ShadowViewColor
{
get { return new UIColor(shadowView.Layer.BackgroundColor); }
set { shadowView.Layer.BackgroundColor = value.CGColor; }
}
public UIViewController CurrentViewController { get; private set; }
UIView mainView
{
get
{
if (CurrentViewController == null)
return null;
return CurrentViewController.View;
}
}
public RootElement NavigationRoot
{
get { return navigation.Root; }
set { EnsureInvokedOnMainThread(delegate { navigation.Root = value; }); }
}
public UITableView NavigationTableView
{
get { return navigation.TableView; }
}
public UIViewController[] ViewControllers
{
get { return viewControllers; }
set
{
EnsureInvokedOnMainThread(delegate
{
viewControllers = value;
NavigationItemSelected(GetIndexPath(SelectedIndex));
});
}
}
public bool IsOpen
{
get {
if (Position == FlyOutNavigationPosition.Left) {
return mainView.Frame.X == menuWidth;
} else {
return mainView.Frame.X == -menuWidth;
}
}
set
{
if (value)
HideMenu();
else
ShowMenu();
}
}
bool ShouldStayOpen
{
get
{
if (ForceMenuOpen || (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad &&
AlwaysShowLandscapeMenu &&
(InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft
|| InterfaceOrientation == UIInterfaceOrientation.LandscapeRight)))
return true;
return false;
}
}
public int SelectedIndex
{
get { return selectedIndex; }
set
{
if (selectedIndex == value)
return;
selectedIndex = value;
EnsureInvokedOnMainThread(delegate { NavigationItemSelected(value); });
}
}
public bool DisableRotation { get; set; }
public override bool ShouldAutomaticallyForwardRotationMethods
{
get { return true; }
}
bool isIos7 = false;
bool isIos8 = false;
class UAUIView : UIView
{
[Export ("accessibilityIdentifier")]
public string AccessibilityId {get;set;}
}
void Initialize(UITableViewStyle navigationStyle = UITableViewStyle.Plain)
{
navigation = new DialogViewController (navigationStyle, null);
navigation.TableView.AccessibilityIdentifier = "FlyoutMenu";
var navFrame = navigation.View.Frame;
navFrame.Width = menuWidth;
if (Position == FlyOutNavigationPosition.Right)
navFrame.X = mainView.Frame.Width - menuWidth;
navigation.View.Frame = navFrame;
View.AddSubview(navigation.View);
TintColor = UIColor.Black;
var version = new System.Version(UIDevice.CurrentDevice.SystemVersion);
isIos8 = version.Major >= 8;
isIos7 = version.Major >= 7;
if(isIos7){
navigation.TableView.TableHeaderView =
new UIView (new CGRect (0, 0, 320, 22)) {
BackgroundColor = UIColor.Clear
};
}
navigation.TableView.TableFooterView = new UIView(new CGRect(0, 0, 100, 100)) {BackgroundColor = UIColor.Clear};
navigation.TableView.ScrollsToTop = false;
shadowView = new UIView(){AccessibilityLabel = "flyOutShadowLayeLabel" , IsAccessibilityElement = true};
shadowView.BackgroundColor = UIColor.Clear;
shadowView.Layer.ShadowOffset = new CGSize(Position == FlyOutNavigationPosition.Left ? -5 : 5, -1);
shadowView.Layer.ShadowColor = UIColor.Black.CGColor;
shadowView.Layer.ShadowOpacity = .75f;
closeButton = new UIButton ();
closeButton.AccessibilityHint = closeButton.AccessibilityIdentifier ="CloseMenu";
closeButton.AccessibilityLabel = "Close Menu";
closeButton.TouchUpInside += CloseButtonTapped;
AlwaysShowLandscapeMenu = true;
NavigationOpenedByLandscapeRotation = false;
View.AddGestureRecognizer (openGesture = new UIScreenEdgePanGestureRecognizer(() => DragContentView (openGesture)){Edges = Position == FlyOutNavigationPosition.Left ? UIRectEdge.Left : UIRectEdge.Right});
View.AddGestureRecognizer (closeGesture = new OpenMenuGestureRecognizer (DragContentView, shouldReceiveTouch));
}
void CloseButtonTapped (object sender, EventArgs e)
{
HideMenu();
}
OpenMenuGestureRecognizer closeGesture;
UIScreenEdgePanGestureRecognizer openGesture;
public event UITouchEventArgs ShouldReceiveTouch;
public bool DisableGesture { get; set; }
internal bool shouldReceiveTouch(UIGestureRecognizer gesture, UITouch touch)
{
if (gesture == closeGesture && !IsOpen)
return false;
if (DisableGesture)
return false;
if (ShouldReceiveTouch != null)
return ShouldReceiveTouch(gesture, touch);
return true;
}
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
CGRect navFrame = GetViewBounds();
// navFrame.Y += UIApplication.SharedApplication.StatusBarFrame.Height;
// navFrame.Height -= navFrame.Y;
//this.statusbar
navFrame.Width = menuWidth;
if (Position == FlyOutNavigationPosition.Right)
navFrame.X = mainView.Frame.Width - menuWidth;
if (navigation.View.Frame != navFrame)
navigation.View.Frame = navFrame;
if (!AlreadyLayedOut)
{
AlreadyLayedOut = true;
if (AlwaysShowLandscapeMenu && (InterfaceOrientation == UIInterfaceOrientation.LandscapeRight || InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft))
NavigationOpenedByLandscapeRotation = true;
if (showMenuBorder)
{
DisplayMenuBorder(mainView.Frame);
}
}
}
public event EventHandler BeginAnimation;
public event EventHandler EndAnimation;
public event EventHandler OpenChanged;
private bool _prevIsOpen = false;
public class OpenChangedEventArgs : EventArgs
{
public OpenChangedEventArgs(bool isOpen){IsOpen = isOpen;}
public bool IsOpen { get; set; }
}
protected virtual void OnBeginAnimation(EventArgs e)
{
EventHandler handler = BeginAnimation;
if (handler != null)
{
handler (this, e);
}
}
protected virtual void OnEndAnimation(EventArgs e)
{
EventHandler handler = EndAnimation;
if(handler != null)
{
handler (this, e);
}
}
protected void CheckRaiseOpenChanged(){
OnEndAnimation (EventArgs.Empty);
if(_prevIsOpen != IsOpen){
OnOpenChanged (new OpenChangedEventArgs (IsOpen));
_prevIsOpen = IsOpen;
}
}
protected virtual void OnOpenChanged(OpenChangedEventArgs e)
{
EventHandler handler = OpenChanged;
if(handler != null)
{
handler (this, e);
}
}
public void DragContentView(UIGestureRecognizer gesture)
{
var panGesture = gesture as UIPanGestureRecognizer;
if (ShouldStayOpen || mainView == null)
return;
if (!HideShadow)
View.InsertSubviewBelow(shadowView, mainView);
navigation.View.Hidden = false;
CGRect frame = mainView.Frame;
shadowView.Frame = frame;
var translation = panGesture.TranslationInView(View).X;
if (panGesture.State == UIGestureRecognizerState.Began)
{
OnBeginAnimation (EventArgs.Empty);
startX = frame.X;
}
else if (panGesture.State == UIGestureRecognizerState.Changed)
{
frame.X = translation + startX;
if (Position == FlyOutNavigationPosition.Left)
{
if (frame.X < 0)
frame.X = 0;
else if (frame.X > menuWidth)
frame.X = menuWidth;
}
else
{
if (frame.X > 0)
frame.X = 0;
else if (frame.X < -menuWidth)
frame.X = -menuWidth;
}
SetLocation(frame);
}
else if (panGesture.State == UIGestureRecognizerState.Ended)
{
var velocity = panGesture.VelocityInView(View).X;
var newX = translation + startX;
bool show = Math.Abs (velocity) > sidebarFlickVelocity ? velocity > 0 : newX > (menuWidth / 2);
if (Position == FlyOutNavigationPosition.Right) {
show = Math.Abs(velocity) > sidebarFlickVelocity ? velocity < 0 : newX < -(menuWidth / 2);
}
if (show) {
ShowMenu ();
} else {
HideMenu ();
}
}
if(!IsOpen && closeButton != null)
closeButton.RemoveFromSuperview();
}
public override void ViewWillAppear(bool animated)
{
CGRect navFrame = navigation.View.Frame;
navFrame.Width = menuWidth;
if (Position == FlyOutNavigationPosition.Right)
navFrame.X = mainView.Frame.Width - menuWidth;
navFrame.Location = CGPoint.Empty;
navigation.View.Frame = navFrame;
View.BackgroundColor = NavigationTableView.BackgroundColor;
var frame = mainView.Frame;
setViewSize ();
SetLocation (frame);
navigation.OnSelection += NavigationItemSelected;
base.ViewWillAppear(animated);
}
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
var frame = mainView.Frame;
setViewSize ();
SetLocation (frame);
}
public override void ViewWillDisappear (bool animated)
{
base.ViewWillDisappear (animated);
navigation.OnSelection -= NavigationItemSelected;
}
protected void NavigationItemSelected(NSIndexPath indexPath)
{
int index = GetIndex(indexPath);
NavigationItemSelected(index);
}
protected void NavigationItemSelected(int index)
{
selectedIndex = index;
if (viewControllers == null || viewControllers.Length <= index || index < 0)
{
if (SelectedIndexChanged != null)
SelectedIndexChanged();
return;
}
if (ViewControllers[index] == null)
{
if (SelectedIndexChanged != null)
SelectedIndexChanged();
return;
}
bool isOpen = false;
if (mainView != null)
{
mainView.RemoveFromSuperview();
isOpen = IsOpen;
}
CurrentViewController = ViewControllers[SelectedIndex];
CGRect frame = GetViewBounds();
if (isOpen || ShouldStayOpen)
frame.X = Position == FlyOutNavigationPosition.Left ? menuWidth : -menuWidth;
View.AddSubview(mainView);
AddChildViewController(CurrentViewController);
setViewSize();
SetLocation(frame);
if (!ShouldStayOpen)
HideMenu();
if (SelectedIndexChanged != null)
SelectedIndexChanged();
}
//bool isOpen {get{ return mainView.Frame.X == menuWidth; }}
public void ShowMenu()
{
if (mainView == null)
return;
EnsureInvokedOnMainThread(delegate
{
//navigation.ReloadData ();
//isOpen = true;
navigation.View.Hidden = false;
shadowView.Frame = mainView.Frame;
if (!ShouldStayOpen)
View.AddSubview(closeButton);
if (!HideShadow)
View.InsertSubviewBelow (shadowView, mainView);
if (ShowMenuBorder)
{
//menuBorder.Frame = mainView.Frame;
//menuBorder.Frame.Width = 1f;
View.InsertSubviewBelow(menuBorder, mainView);
}
});
OnBeginAnimation (EventArgs.Empty);
UIView.Animate(.2, () =>
{
UIView.SetAnimationCurve(UIViewAnimationCurve.EaseIn);
CGRect frame = mainView.Frame;
frame.X = Position == FlyOutNavigationPosition.Left ? menuWidth : -menuWidth;
setViewSize();
SetLocation(frame);
shadowView.Frame = frame;
}, showComplete);
}
void showComplete()
{
CheckRaiseOpenChanged ();
}
void setViewSize()
{
CGRect frame = GetViewBounds();
frame.Width -= ShouldStayOpen ? menuWidth : 0;
mainView.Bounds = frame;
DisplayMenuBorder(mainView.Frame);
}
CGRect GetViewBounds()
{
CGRect frame = View.Bounds;
if ((InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight)) {
#if UNIFIED || __UNIFIED__
var width = NMath.Max (frame.Width, frame.Height);
#else
var width = Math.Max(frame.Width, frame.Height);
#endif
#if UNIFIED || __UNIFIED__
var height = NMath.Min (frame.Width, frame.Height);
#else
var height = Math.Min(frame.Width, frame.Height);
#endif
frame.Width = width;
frame.Height = height;
}
return frame;
}
void SetLocation(CGRect frame)
{
mainView.Layer.AnchorPoint = new CGPoint(.5f, .5f);
frame.Y = 0;
if (mainView.Frame.Location == frame.Location)
return;
frame.Size = mainView.Frame.Size;
var center = new CGPoint(frame.Left + frame.Width/2,
frame.Top + frame.Height/2);
mainView.Center = center;
shadowView.Center = center;
closeButton.Frame = mainView.Frame;
DisplayMenuBorder(frame);
}
private void DisplayMenuBorder(CGRect frame)
{
if (ShowMenuBorder && menuBorder == null)
{
menuBorder = new UIView();
menuBorder.BackgroundColor = menuBorderColor;
View.InsertSubviewAbove(menuBorder, mainView);
}
if (ShowMenuBorder)
{
CGRect borderFrame = new CGRect();
// MDR 29/08/2014 - Prevent bottom part of border missing momentarily after rotate from landscape to portrait
borderFrame.Height = UIScreen.MainScreen.Bounds.Height;
borderFrame.Width = 1f;
borderFrame.X = frame.X - 1f;
//borderFrame.X = navigation.View.Frame.Right + 1f;
borderFrame.Y = 0;
menuBorder.Frame = borderFrame;
}
}
public void HideMenu()
{
if (mainView == null || mainView.Frame.X == 0 || ShouldStayOpen) {
closeButton.RemoveFromSuperview();
return;
}
EnsureInvokedOnMainThread(delegate
{
//isOpen = false;
navigation.FinishSearch();
closeButton.RemoveFromSuperview();
UIView.Animate(.2, () =>
{
UIView.SetAnimationCurve(UIViewAnimationCurve.EaseInOut);
CGRect frame = GetViewBounds();
frame.X = 0;
setViewSize();
SetLocation(frame);
shadowView.Frame = frame;
}, hideComplete);
});
}
[Export("animationEnded")]
void hideComplete()
{
shadowView.RemoveFromSuperview();
navigation.View.Hidden = true;
CheckRaiseOpenChanged ();
}
public void ResignFirstResponders(UIView view)
{
if (view.Subviews == null)
return;
foreach (UIView subview in view.Subviews)
{
if (subview.IsFirstResponder)
subview.ResignFirstResponder();
ResignFirstResponders(subview);
}
}
public void ToggleMenu()
{
EnsureInvokedOnMainThread(delegate
{
if (!IsOpen && CurrentViewController != null && CurrentViewController.IsViewLoaded)
ResignFirstResponders(CurrentViewController.View);
if (IsOpen)
{
HideMenu();
NavigationOpenedByLandscapeRotation = false;
}
else
ShowMenu();
});
}
int GetIndex(NSIndexPath indexPath)
{
int section = 0;
int rowCount = 0;
while (section < indexPath.Section)
{
rowCount += navigation.Root[section].Count;
section ++;
}
return rowCount + indexPath.Row;
}
protected NSIndexPath GetIndexPath(int index)
{
if (navigation.Root == null)
return NSIndexPath.FromRowSection(0, 0);
int currentCount = 0;
int section = 0;
foreach (Section element in navigation.Root)
{
if (element.Count + currentCount > index)
break;
currentCount += element.Count;
section ++;
}
int row = index - currentCount;
return NSIndexPath.FromRowSection(row, section);
}
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
if (DisableRotation)
return toInterfaceOrientation == InterfaceOrientation;
UIInterfaceOrientationMask mask = CurrentViewController.GetSupportedInterfaceOrientations();
UIInterfaceOrientation orientation = CurrentViewController.PreferredInterfaceOrientationForPresentation();
bool theReturn = CurrentViewController == null
? true
: CurrentViewController.ShouldAutorotateToInterfaceOrientation(toInterfaceOrientation);
if (CurrentViewController != null)
Debug.WriteLine("Should auto rotate: " + toInterfaceOrientation.ToString() + ": " + theReturn);
else
Debug.WriteLine("Should auto rotate: View is null");
return theReturn;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
if (CurrentViewController != null)
return CurrentViewController.GetSupportedInterfaceOrientations();
return UIInterfaceOrientationMask.All;
}
public override void WillRotate(UIInterfaceOrientation toInterfaceOrientation, double duration)
{
base.WillRotate(toInterfaceOrientation, duration);
}
public override void DidRotate(UIInterfaceOrientation fromInterfaceOrientation)
{
base.DidRotate(fromInterfaceOrientation);
// mribbons@github - 28/08/2014 - Fix menu width size chunk of shadowView missing when rotating to portait mode
shadowView.Frame = mainView.Frame;
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
return;
// mribbons@github - 28/08/2014 - Only do this is should stay open is false.
// Note that this doesn't seem to work well anyway, menu shows and hides, or doesn't hide when switching to portrait (can't recall which but depends how AlwaysShowLandscapeMenu and ForceMenuOpen are set)
if (AlwaysShowLandscapeMenu)
{
switch (InterfaceOrientation)
{
case UIInterfaceOrientation.LandscapeLeft:
case UIInterfaceOrientation.LandscapeRight:
if (!IsOpen)
{
NavigationOpenedByLandscapeRotation = true;
ShowMenu();
}
return;
default:
// mribbons@github - 28/08/2014 - Only close the menu if it was opened by rotating
if (NavigationOpenedByLandscapeRotation)
{
NavigationOpenedByLandscapeRotation = false;
HideMenu();
}
else
{
DisplayMenuBorder(mainView.Frame);
}
return;
}
}
}
public override void WillAnimateRotation(UIInterfaceOrientation toInterfaceOrientation, double duration)
{
base.WillAnimateRotation(toInterfaceOrientation, duration);
}
protected void EnsureInvokedOnMainThread(Action action)
{
if (IsMainThread())
{
action();
return;
}
BeginInvokeOnMainThread(() =>
action()
);
}
static bool IsMainThread()
{
return NSThread.Current.IsMainThread;
//return Messaging.bool_objc_msgSend(GetClassHandle("NSThread"), new Selector("isMainThread").Handle);
}
protected override void Dispose (bool disposing)
{
base.Dispose (disposing);
SelectedIndexChanged = null;
if(ShouldReceiveTouch != null)
foreach (var d in ShouldReceiveTouch.GetInvocationList ())
ShouldReceiveTouch -= (UITouchEventArgs)d;
View.RemoveGestureRecognizer (closeGesture);
closeButton.TouchUpInside -= CloseButtonTapped;
closeButton = null;
if (this.CurrentViewController != null) {
this.CurrentViewController.View.RemoveFromSuperview ();
}
}
}
}