1- import React from 'react' ;
2- import { StyleSheet } from 'react-native' ;
1+ import React , { Component } from 'react' ;
2+ import { ScrollView , StyleSheet } from 'react-native' ;
33import { observer } from 'mobx-react' ;
44import PropTypes from 'prop-types' ;
55import Background from '../component/background' ;
66import { Header , Title } from '../component/header' ;
77import Text from '../component/text' ;
8- import { List , ListContent } from '../component/list' ;
98import { Button , BackButton } from '../component/button' ;
109import { color , font } from '../component/style' ;
1110
1211//
1312// CLI View
1413//
1514
15+ const styles = StyleSheet . create ( {
16+ header : {
17+ marginBottom : 1 , // display separator above output background color
18+ } ,
19+ } ) ;
20+
1621const CLIView = ( { store, nav } ) => (
1722 < Background color = { color . blackDark } >
18- < Header separator >
23+ < Header separator style = { styles . header } >
1924 < BackButton onPress = { ( ) => nav . goSettings ( ) } />
2025 < Title title = "Logs" />
2126 < Button disabled onPress = { ( ) => { } } />
2227 </ Header >
23- < Background color = { color . cliBackground } >
24- < ListContent >
25- < List
26- data = { store . logs . slice ( ) }
27- renderItem = { text => < LogItem text = { text } /> }
28- scrollToEnd = { true }
29- />
30- </ ListContent >
31- </ Background >
28+ < LogOutput logs = { store . logs . slice ( ) } />
3229 </ Background >
3330) ;
3431
@@ -37,17 +34,46 @@ CLIView.propTypes = {
3734 nav : PropTypes . object . isRequired ,
3835} ;
3936
40- const iStyles = StyleSheet . create ( {
37+ //
38+ // Log Output
39+ //
40+
41+ const logStyles = StyleSheet . create ( {
42+ content : {
43+ flexGrow : 1 ,
44+ backgroundColor : color . cliBackground ,
45+ paddingTop : 25 ,
46+ paddingBottom : 25 ,
47+ paddingLeft : 50 ,
48+ paddingRight : 50 ,
49+ } ,
4150 text : {
42- textAlign : 'left' ,
4351 fontSize : font . sizeS ,
4452 } ,
4553} ) ;
4654
47- const LogItem = ( { text } ) => < Text style = { iStyles . text } > { text } </ Text > ;
55+ class LogOutput extends Component {
56+ constructor ( props ) {
57+ super ( props ) ;
58+ this . _ref = React . createRef ( ) ;
59+ }
60+
61+ get printLogs ( ) {
62+ setTimeout ( ( ) => this . _ref . current . scrollToEnd ( ) , 50 ) ;
63+ return this . props . logs . map ( l => l . replace ( / \s + $ / , '' ) ) . join ( '\n' ) ;
64+ }
65+
66+ render ( ) {
67+ return (
68+ < ScrollView ref = { this . _ref } contentContainerStyle = { logStyles . content } >
69+ < Text style = { logStyles . text } > { this . printLogs } </ Text >
70+ </ ScrollView >
71+ ) ;
72+ }
73+ }
4874
49- LogItem . propTypes = {
50- text : PropTypes . string ,
75+ LogOutput . propTypes = {
76+ logs : PropTypes . array . isRequired ,
5177} ;
5278
5379export default observer ( CLIView ) ;
0 commit comments