Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit c0fb552

Browse files
Make logs always scroll to bottom + limit to 100
1 parent 67dd4a1 commit c0fb552

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/action/log.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class LogAction {
1515
_ipcRenderer = ipcRenderer;
1616
_ipcRenderer.on('logs', (event, arg) => {
1717
store.logs.push(arg);
18+
if (store.logs.length > 100) {
19+
store.logs.splice(0, store.logs.length - 100);
20+
}
1821
});
1922
_ipcRenderer.send('logs-ready', true);
2023
}

src/component/list.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,15 @@ export class List extends Component {
5353
render() {
5454
return (
5555
<ListView
56+
ref={component => (this.list = component)}
5657
dataSource={this.dataSource}
5758
renderHeader={this.props.renderHeader}
58-
renderRow={this.props.renderItem}
59+
renderRow={data => {
60+
this.props.scrollToEnd
61+
? setTimeout(() => this.list._scrollViewRef.scrollToEnd(), 50)
62+
: null;
63+
return this.props.renderItem(data);
64+
}}
5965
enableEmptySections={true}
6066
/>
6167
);
@@ -66,6 +72,7 @@ List.propTypes = {
6672
data: PropTypes.array.isRequired,
6773
renderHeader: PropTypes.func,
6874
renderItem: PropTypes.func.isRequired,
75+
scrollToEnd: PropTypes.bool,
6976
};
7077

7178
//

src/view/cli.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import { StyleSheet } from 'react-native';
3+
import { observer } from 'mobx-react';
34
import PropTypes from 'prop-types';
45
import Background from '../component/background';
5-
import MainContent from '../component/main-content';
66
import { Header, Title } from '../component/header';
77
import Text from '../component/text';
8+
import { List, ListContent } from '../component/list';
89
import { Button, BackButton } from '../component/button';
910
import { color, font } from '../component/style';
1011

@@ -29,9 +30,13 @@ const CLIView = ({ store, nav }) => (
2930
<Button disabled onPress={() => {}} />
3031
</Header>
3132
<Background color={color.cliBackground}>
32-
<MainContent style={styles.content}>
33-
{store.logs.map((log, i) => <LogItem text={log} key={i} />)}
34-
</MainContent>
33+
<ListContent>
34+
<List
35+
data={store.logs.slice()}
36+
renderItem={text => <LogItem text={text} />}
37+
scrollToEnd={true}
38+
/>
39+
</ListContent>
3540
</Background>
3641
</Background>
3742
);
@@ -54,4 +59,4 @@ LogItem.propTypes = {
5459
text: PropTypes.string,
5560
};
5661

57-
export default CLIView;
62+
export default observer(CLIView);

0 commit comments

Comments
 (0)