Skip to content

Commit 397b98e

Browse files
author
amoreno
committed
Resolve #4 issue
1 parent e5e7d44 commit 397b98e

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

Example/index.android.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class Example extends React.PureComponent<{}> {
1818
<View style={styles.container}>
1919
<Button title="Open" onPress={this._onPressButton} />
2020
<BottomSheet
21-
refs={(ref: BottomSheet) => {
21+
ref={(ref: BottomSheet) => {
2222
this.bottomSheet = ref
2323
}}
2424
itemDivider={3}

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
# react-native-js-bottom-sheet
2+
23
Modal bottom sheet component for Android that follows the guidelines of Material Design.
34

45
https://material.io/guidelines/components/bottom-sheets.html
56

6-
![alt text](./example.png)
7+
<p align="center">
8+
<img src="./example.png" alt="Stepper" width="400">
9+
</p>
10+
11+
## Getting startedgit s
712

8-
## Getting started
913
```sh
1014
$ yarn add react-native-js-bottom-sheet
1115
```
16+
1217
## Usage
18+
1319
Code refers to the previous image example:
1420

1521
```js
16-
1722
/* @flow */
1823

1924
import React, { Component } from 'react'
@@ -34,7 +39,7 @@ export default class Example extends Component {
3439
<View style={styles.container}>
3540
<Button title="Open" onPress={this._onPressButton} />
3641
<BottomSheet
37-
refs={(ref: BottomSheet) => {
42+
ref={(ref: BottomSheet) => {
3843
this.bottomSheet = ref
3944
}}
4045
itemDivider={3}
@@ -93,8 +98,9 @@ export default class Example extends Component {
9398
```
9499

95100
## API
101+
96102
| Prop | Type | Required | Description |
97-
|-------------------|---------------|----------|--------------------------------------------------------------------------------------------------------------------------|
103+
| ----------------- | ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
98104
| coverScreen | bool | No | Will use RN Modal component to cover the entire screen wherever the modal is mounted in the component hierarchy |
99105
| backButtonEnabled | bool | No | Close modal when receiving back button event |
100106
| height | number | No | Height of the container. By default it has no height, due to container grows automatically depending of list of elements |
@@ -103,15 +109,16 @@ export default class Example extends Component {
103109
| fontFamily | string | No | Used to display values. By default is Roboto |
104110
| titleFontFamily | string | No | Title font family |
105111
| isOpen | bool | No | Specifies if bottom sheet is open by default |
106-
| refs | Function | Yes | |
107112
| itemDivider | number | No | Insert an item separator below the specified item number |
108113

109114
## License
115+
110116
MIT License
111117

112118
Copyright (c) 2017 InterfaceKit
113119

114120
## Author
121+
115122
Antonio Moreno Valls `<amoreno at apsl.net>`
116123

117124
Built with 💛 by [APSL](https://github.com/apsl).

example.png

-11.8 KB
Loading

lib/BottomSheet.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
PixelRatio,
1212
View
1313
} from 'react-native'
14-
1514
import Modal from 'react-native-modalbox'
1615

1716
type Props = {
@@ -21,17 +20,15 @@ type Props = {
2120
height?: number,
2221
title?: string,
2322
options: Array<Object>,
24-
refs: Function,
2523
fontFamily?: string,
2624
titleFontFamily?: string,
2725
isOpen?: boolean,
2826
cancelButtonIndex?: number,
2927
itemDivider?: number
3028
}
31-
type State = void
3229

33-
class BottomSheet extends React.PureComponent<Props, State> {
34-
open: Function
30+
class BottomSheet extends React.PureComponent<Props> {
31+
bottomSheet: Modal
3532

3633
static propTypes = {
3734
styleContainer: PropTypes.object,
@@ -40,7 +37,6 @@ class BottomSheet extends React.PureComponent<Props, State> {
4037
height: PropTypes.number,
4138
title: PropTypes.string,
4239
options: PropTypes.arrayOf(PropTypes.object).isRequired,
43-
refs: PropTypes.func.isRequired,
4440
fontFamily: PropTypes.string,
4541
titleFontFamily: PropTypes.string,
4642
isOpen: PropTypes.bool,
@@ -70,6 +66,20 @@ class BottomSheet extends React.PureComponent<Props, State> {
7066
})
7167
}
7268

69+
/**
70+
* Open the BottomSheet
71+
*/
72+
open() {
73+
this.bottomSheet.open()
74+
}
75+
76+
/**
77+
* Close the BottomSheet
78+
*/
79+
close() {
80+
this.bottomSheet.close()
81+
}
82+
7383
renderTitle = () => {
7484
if (!this.props.title) {
7585
return
@@ -88,11 +98,13 @@ class BottomSheet extends React.PureComponent<Props, State> {
8898
}
8999
return (
90100
<Modal
101+
ref={(ref: any) => {
102+
this.bottomSheet = ref
103+
}}
91104
style={[this.props.styleContainer, { height: this.props.height }]}
92105
backButtonClose={this.props.backButtonEnabled}
93106
position="bottom"
94107
isOpen={this.props.isOpen}
95-
ref={this.props.refs}
96108
coverScreen={this.props.coverScreen}>
97109
<ScrollView style={styles.modal}>
98110
{this.renderTitle()}

0 commit comments

Comments
 (0)