-
Notifications
You must be signed in to change notification settings - Fork 433
Better props #175
base: feature/better-props
Are you sure you want to change the base?
Better props #175
Changes from all commits
14dff14
8f93442
d8509d7
b90e0ff
613e9dc
9265966
e3e6903
a659f11
0ad70cf
d9dccf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ class ContentView extends React.Component { | |
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<TouchableOpacity onPress={this.props.onMenuButtonPress}> | ||
<Text>Open menu</Text> | ||
</TouchableOpacity> | ||
<Text style={styles.welcome}> | ||
Welcome to React Native! | ||
</Text> | ||
|
@@ -38,12 +41,26 @@ class ContentView extends React.Component { | |
} | ||
|
||
class Application extends React.Component { | ||
state = { | ||
isOpen: false, | ||
}; | ||
|
||
closeMenu() { | ||
this.setState({ isOpen: false }); | ||
} | ||
|
||
toggleMenu() { | ||
this.setState({ isOpen: !this.state.isOpen }); | ||
} | ||
|
||
render() { | ||
const menu = <Menu navigator={navigator}/>; | ||
const menu = <Menu navigator={navigator} />; | ||
|
||
return ( | ||
<SideMenu menu={menu}> | ||
<ContentView/> | ||
<SideMenu | ||
menu={menu} | ||
onContentPress={() => this.closeMenu()}> | ||
<ContentView onMenuButtonPress={() => this.toggleMenu()}/> | ||
</SideMenu> | ||
); | ||
} | ||
|
@@ -58,9 +75,9 @@ class Application extends React.Component { | |
- `edgeHitWidth` (Number) - Edge distance on content view to open side menu, defaults to 60 | ||
- `toleranceX` (Number) - X axis tolerance | ||
- `toleranceY` (Number) - Y axis tolerance | ||
- `disableGestures` (Bool) - Disable whether the menu can be opened with gestures or not | ||
- `onStartShouldSetResponderCapture` (Function) - Function that accepts event as an argument and specify if side-menu should react on the touch or not. Check https://facebook.github.io/react-native/docs/gesture-responder-system.html for more details | ||
- `onChange` (Function) - Callback on menu open/close. Is passed `isOpen` as an argument | ||
- `onSwipe` (Function) - Function that handles gestures, receives boolean argument indicating whether menu should be opened or not based on the drag. When not defined, gestures are disabled | ||
- `onStartShouldSetResponderCapture` (Function) - Function that accepts event as an argument and specify if side-menu should react on the touch or not. Check https://facebook.github.io/react-native/docs/gesture-responder-system.html for more details. Typically you would like to set `isOpen` value to the passed argument (see examples/Basic.js) | ||
- `onContentPress` (Function) - Function that handles content press when menu is opened. Typically you would set isOpen to false inside it (see examples/Basic.js). When not present, content is accessible when menu is opened and there's no `touchToClose` behavior | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you think we should make content accessible? Can you explain what motivated you to rewrite this behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing made me to change it. I just think it's better to make that function optional, not required. It does not hurt anyone and makes SideMenu easier to set up. When there's no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it's a bit different from what I see: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reasons for that are described in the PR description. Currently menu is still not props driven. Currently it uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, you don't have any access to the local state from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Menu should not have any state nor that weird isOpen thing. We said that menu was going to be props driven which is not true currently, because it still keeps it's own To me, that's reasonable refactor, removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's entirely props driven, But why I don't understand why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why you think that So literally, you want to make it possible to control an offset from the parent component? Like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@grabbou I need this exact thing right now. When i open the menu |
||
- `menuPosition` (String) - either 'left' or 'right', defaults to 'left' | ||
- `animationFunction` (Function -> Object) - Function that accept 2 arguments (prop, value) and return an object: | ||
- `prop` you should use at the place you specify parameter to animate | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, can you explain me how this one works? Not sure I understand it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a function called when you drag menu with gesture. It's called with Boolean argument indicating whether menu is about to open or not. When you slide from left to open it, it will be called with
true
- menu is about to open. Now - if you want to open it, just update the state with that value (as per example). If you app is more advanced, you can embed some additional logic inside and sometimes set false under certain conditions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't know if the menu is going to be opened or not, right? We can assert that menu is going to be closed or opened only at the moment when we release it (based on calculations we make).
Why do you think we need to give user a change if menu should be opened or not? I think it can be configured by the offsets user can setup.
Do you think it's a transparent behavior if function is not defined - assume that we don't want to enable gestures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We know based on the calculations we do currently. It's just that instead of
this.isOpen = someBooleanValue
assignment we use a callback and pass thatsomeBooleanValue
up.That's what we do now. If that function is not defined, gestures are disabled.
Because that PR removes
this.isOpen
from component completely. Side menu has no internal state nor does not store any informations about whether it's open or not. It has to use a callback so that parent component updates state andthis.props.isOpen
reflects new position.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain me how in this case (the case we don't have
isOpen
at all) we should approach menu opening using an external button (instead of swiping gesture)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like in examples/Basic :) onPress handler and parent component state update (or even redux call)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you want to force uses to write this animation by hand somewhere in reducers and run the full loop every frame?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite, let's discuss that on Skype tomorrow :D