-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First iteration of a Star component #28
Conversation
Looking gorgeos btw :) |
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.
Left some questions, basically on how we plan to use this.
So far looking amazing.
@@ -1,5 +1,3 @@ | |||
/* global require */ |
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.
This change should be out of this pr, but we have seen others things in this repo right ? ;)
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.
I can make this change part of the eslint pr.
} | ||
|
||
render() { | ||
const img = this.state.value ? |
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.
Isn't it easy to read something like:
const imgSource = this.state.value ? './assets/star.png' : './assets/star-border.png';
...
<Image source={require(imgSource)}/>```
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.
Does it work this way? I tried a few days ago and it didn't work. require()
has to be static.
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.
Correct dynamic require doesn't work. I think it might be best to import the assets at the top of the file to make this clear.
const images = {
empty: require('./assets/star-empty.png'),
full: require('./assets/star-full.png'),
};
... later
render() {
return <Image source={ this.state.value ? images.full : images.empty }/>
}
return ( | ||
<TouchableOpacity | ||
style={styles.container} | ||
onPress={this.toggle}> |
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.
Should we add a callback property to inform the user of this component that the toggle happened therefore an action following that 'starred' can happened?
Or do you prefer the opposite logic, perform an action in the parent component and when that action is finished change the property used to show the start?
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.
I think the component can communicate directly with Redux. This way there's no other wiring required than passing an itemId
to this component.
Or... was it your question?
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.
I spoke with @arcturus about an idea for component design. We can have a dumb component that is just a <Star selected={true}/> that toggles between
trueand
false. But then we can wrap that in a
` component that wires the component into the app's Redux store.
This means that we could drop a <MagnetStar>
anywhere in the app and it'll "just work".
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.
I think in Redux world they call <MagnetStar>
style components: "container components". The don't have any visual properties, they just act as a data provider.
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.
Yes that makes sense.
I would only argue that the scenes are container components and we don't need to wrap this Star component inside another container.
Forgot to mention, once this work is done (with all iterations) we can close #14 |
f4c34eb
to
5d59b91
Compare
@gmarty can you check-in the source SVG too so that anyone can export different sizes/colours if need be? |
8ce9bf5
to
1c49bba
Compare
I did the change requested. We can implement the logic in a subsequent pull request. |
This is only a first iteration of this component. Things missing include: