Пример #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Skip.SetTitle(Resources.Skip.ToUpper(), UIControlState.Normal);
            Next.SetTitle(Resources.Next.ToUpper(), UIControlState.Normal);
            Previous.SetTitle(Resources.Back.ToUpper(), UIControlState.Normal);

            preparePlaceholders();

            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                var navigationBarHeight = NavigationController.NavigationBar.Frame.Height;
                AdditionalSafeAreaInsets = new UIEdgeInsets(-navigationBarHeight, 0, 0, 0);
            }

            PageControl.Pages    = ViewModel.NumberOfPages;
            FirstPageLabel.Text  = Resources.OnboardingTrackPageCopy;
            SecondPageLabel.Text = Resources.OnboardingMostUsedPageCopy;
            ThirdPageLabel.Text  = Resources.OnboardingReportsPageCopy;

            Skip.Rx()
            .BindAction(ViewModel.SkipOnboarding)
            .DisposedBy(DisposeBag);

            Next.Rx()
            .BindAction(ViewModel.GoToNextPage)
            .DisposedBy(DisposeBag);

            Previous.Rx()
            .BindAction(ViewModel.GoToPreviousPage)
            .DisposedBy(DisposeBag);

            ScrollView.Rx()
            .DecelerationEnded()
            .Select(_ => (int)(ScrollView.ContentOffset.X / ScrollView.Frame.Width))
            .Subscribe(newPage => ViewModel?.ChangePage(newPage))
            .DisposedBy(DisposeBag);

            ViewModel.BackgroundColor
            .Select(color => color.ToNativeColor())
            .Subscribe(View.Rx().AnimatedBackgroundColor())
            .DisposedBy(DisposeBag);

            ViewModel.BorderColor
            .Select(color => color.ToNativeColor())
            .Subscribe(PhoneFrame.Rx().AnimatedBackgroundColor())
            .DisposedBy(DisposeBag);

            ViewModel.CurrentPage
            .Select(backgroundImageForPage)
            .Subscribe(image => BackgroundImage.Image = image)
            .DisposedBy(DisposeBag);

            ViewModel.IsLastPage
            .Invert()
            .Subscribe(Skip.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.IsFirstPage
            .Invert()
            .Subscribe(Previous.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.IsTrackPage
            .Subscribe(trackPagePlaceholder.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.IsReportPage
            .Subscribe(reportsPagePlaceholder.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.IsSummaryPage
            .Subscribe(mostUsedPagePlaceholder.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.CurrentPage
            .Subscribe(p => PageControl.CurrentPage = p)
            .DisposedBy(DisposeBag);

            ViewModel.CurrentPage
            .Subscribe(p =>
            {
                var scrollPoint = new CGPoint(ScrollView.Frame.Size.Width * p, 0);
                ScrollView.SetContentOffset(scrollPoint, true);
            })
            .DisposedBy(DisposeBag);
        }