import { Options } from '@ulangi/react-native-navigation' ; import { ActivityState , ReviewPriority , ScreenName , Theme , } from '@ulangi/ulangi-common/enums' ; import { ObservableFeedbackListState , ObservableReviewActionBarState , ObservableReviewFeedbackBarState , ObservableTitleTopBar , ObservableTopBarButton , ObservableVocabulary , ObservableWritingFormState , ObservableWritingLessonScreen , ObservableWritingResult , } from '@ulangi/ulangi-observable' ; import { ObservableMap , observable } from 'mobx' ; import { observer } from 'mobx-react' ; import * as React from 'react' ; import { Container , ContainerPassedProps } from '../../Container' ; import { Images } from '../../constants/Images' ; import { config } from '../../constants/config' ; import { WritingLessonScreenIds } from '../../constants/ids/WritingLessonScreenIds' ; import { WritingLessonScreenFactory } from '../../factories/writing/WritingLessonScreenFactory' ; import { WritingQuestionIterator } from '../../iterators/WritingQuestionIterator' ; import { WritingLessonScreen } from './WritingLessonScreen' ; import { WritingLessonScreenStyle } from './WritingLessonScreenContainer.style' ; export interface WritingLessonScreenPassedProps { readonly vocabularyList : ObservableMap < string , ObservableVocabulary > ; readonly currentCategoryNames : undefined | readonly string [ ] ; readonly startLesson : ( overrideReviewPriority : undefined | ReviewPriority ) => void ; } @ observer export class WritingLessonScreenContainer extends Container < WritingLessonScreenPassedProps > { public static options ( props ) { return props . theme === Theme . LIGHT ? WritingLessonScreenStyle . SCREEN_FULL_LIGHT_STYLES : WritingLessonScreenStyle . SCREEN_FULL_DARK_STYLES ; } private screenFactory = new WritingLessonScreenFactory ( this . props , this . eventBus , this . observer ) ; private questionIterator = new WritingQuestionIterator ( this . props . passedProps . vocabularyList ) ; private writingSettingsDelegate = this . screenFactory . createWritingSettingsDelegate ( ) ; private currentSettings = this . writingSettingsDelegate . getCurrentSettings ( ) ; protected observableScreen = new ObservableWritingLessonScreen ( 0 , this . props . passedProps . vocabularyList , new ObservableWritingFormState ( false , null , this . questionIterator . current ( ) , '' , '' , 0 , this . questionIterator . getNumberOfQuestions ( ) , 0 , false ) , new ObservableWritingResult ( config . writing . gradeScale , observable . array ( [ ] ) , observable . array ( [ ] ) , observable . array ( [ ] ) , observable . array ( [ ] ) ) , new ObservableFeedbackListState ( observable . map ( ) ) , new ObservableReviewActionBarState ( observable . array ( [ ] ) ) , new ObservableReviewFeedbackBarState ( observable . map ( ) ) , observable . box ( this . currentSettings . feedbackButtons ) , observable . box ( this . currentSettings . autoplayAudio ) , observable . box ( this . currentSettings . highlightOnError ) , observable . box ( false ) , observable . box ( ActivityState . INACTIVE ) , observable . box ( ActivityState . INACTIVE ) , this . props . componentId , ScreenName . WRITING_LESSON_SCREEN , new ObservableTitleTopBar ( 'Writing' , new ObservableTopBarButton ( WritingLessonScreenIds . BACK_BTN , null , { light : Images . ARROW_LEFT_BLACK_22X22 , dark : Images . ARROW_LEFT_MILK_22X22 , } , ( ) : void => { this . screenDelegate . handleBackPressed ( ) ; } ) , new ObservableTopBarButton ( WritingLessonScreenIds . END_BTN , 'End' , null , ( ) : void => { this . screenDelegate . endLesson ( ) ; } ) ) ) ; protected navigatorDelegate = this . screenFactory . createNavigatorDelegate ( ) ; protected screenDelegate = this . screenFactory . createScreenDelegate ( this . observableScreen , this . questionIterator , this . props . passedProps . currentCategoryNames , this . props . passedProps . startLesson ) ; protected onThemeChanged ( theme ) { this . navigatorDelegate . mergeOptions ( theme === Theme . LIGHT ? WritingLessonScreenStyle . SCREEN_LIGHT_STYLES_ONLY : WritingLessonScreenStyle . SCREEN_DARK_STYLES_ONLY ) ; } public componentDidMount ( ) { this . screenDelegate . setUp ( ) ; } public componentWillUnmount ( ) { this . screenDelegate . cleanUp ( ) ; } public componentDidAppear ( ) { this . observableScreen . screenAppearedTimes += 1 ; if ( this . observableScreen . screenAppearedTimes === 1 ) { this . observableScreen . writingFormState . shouldAutoFocus = this . currentSettings . autoShowKeyboard ; } } public render ( ) { return ( < WritingLessonScreen themeStore = { this . props . rootStore . themeStore } observableScreen = { this . observableScreen } screenDelegate = { this . screenDelegate } / > ) ; } }