Xamarin ebook reader page navigation architecture

I am developing a Xamarin. I want to ask you for some advice on the architecture of page navigation. My application consists of a main page that contains a list of books, a page that contains chapters of a particular book, pages that display the page text.

My home page is a custom page that inherits from ContentPage

.

/// <summary>
    /// The home page of the application.
    /// </summary>
    public class MainPage : ContentPage
    {
        private readonly StackLayout panel;

        /// <summary>
        /// The collection of books.
        /// </summary>
        private IEnumerable<EpubBook> books;

        /// <summary>
        /// Initialize an instance of the <see cref="MainPage"/>
        /// </summary>
        /// <param name="books">The collection of books.</param>
        public MainPage(IEnumerable<EpubBook> books)
        {
            this.Title = "Main page";
            this.books = books;
            this.panel = new StackLayout();

            foreach (EpubBook book in this.books)
            {
                OpenBookButton openBookButton = new OpenBookButton(book)
                {
                    Text = $"Title: {book.Title}"
                };

                openBookButton.Clicked += OnClickOpenBookButton;
                this.panel.Children.Add(openBookButton);
            }

            this.Content = new ScrollView
            {
                Content = this.panel,
                Orientation = ScrollOrientation.Vertical
            };
        }

        private async void OnClickOpenBookButton(object sender, EventArgs e)
        {
            OpenBookButton button = (OpenBookButton) sender;
            BookContentPage bookContentPage = new BookContentPage(button.Book.Chapters);
await this.Navigation.PushAsync(bookContentPage);
        }
    }

      

This is my page that displays all the chapters of the book.

public class BookContentPage : ContentPage
    {
        private readonly StackLayout panel;

        public BookContentPage(List<EpubChapter> chapters)
        {
            this.Title = "Content page";
            this.panel = new StackLayout();

            foreach (EpubChapter chapter in chapters)
            {
                this.WriteChapter(chapter, panel);
            }

            this.Content = new ScrollView
            {
                Content = panel
            };
        }

        private void WriteChapter(EpubChapter epubChapter, Layout<View> layout)
        {
            // create buttons which have a text which displays the name of the chapter
        }

        private void OnClickOpenBookChapterButton(object sender, EventArgs args)
        {    
            OpenBookChapterButton button = (OpenBookChapterButton) sender;
            BookTextPage bookTextPage = new BookTextPage(button.Chapter);
            this.Navigation.PushAsync(bookTextPage);

            // I want to split bookTextPage to few little screen pages in the future

            this.Navigation.PushAsync(bookTextPage);
        }
    }

      

Eventually I want to split the book text into pages and create CarouselPage

one that will contain all these pages. What do you think about my development of this application? I am new to Xamarin.Forms

. Am I on the right track? What did I do wrong and what needs to be fixed in my approach?

+3


source to share


1 answer


CarouselPage will be deprecated shortly, so you'll want to switch to CarouselView . Using this control, the architecture of the page will be pretty light.



You have one ContentPage for the book list. Then when you click on one go to another ContentPage that has a CarouselView inside. This will be linked to a list of pages in your book, after which they can be flipped.

+1


source







All Articles