Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Select image
Browse files Browse the repository at this point in the history
  • Loading branch information
whs committed May 3, 2016
1 parent 4634460 commit c72cf32
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This project is from mobile software development class.
- [ ] Corners
- [x] Add slide
- [x] Slide editing
- [ ] Change background image
- [x] Change background image
- [ ] Select background color
- [ ] Select text color
- [ ] Multiplatform
Expand Down
4 changes: 3 additions & 1 deletion components/App/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import FileList from '../FileList';
import BackStack from '../BackStack';
import Editor from '../Editor';
import ImagePicker from '../ImagePicker';
import ImagePreview from '../ImagePreview';

export default class App extends Component {
static routes = {
FileList: FileList,
Editor: Editor,
ImagePicker: ImagePicker,
ImagePreview: ImagePreview,
};

componentDidMount(){
Expand Down Expand Up @@ -50,4 +52,4 @@ export default class App extends Component {
route: route,
});
}
}
}
11 changes: 10 additions & 1 deletion components/Editor/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export default class Editor extends Component {
}

_onImagePickerButton = () => {
this.props.navigator.push({name: 'ImagePicker', index: this.props.index + 1});
this.props.navigator.push({
name: 'ImagePicker', index: this.props.index + 1,
callback: this._onImagePicked,
});
};

_onPreviewButton = () => {
Expand Down Expand Up @@ -118,4 +121,10 @@ export default class Editor extends Component {
};
});
};

_onImagePicked = (url) => {
Realm.write(() => {
this.file.slides[this.state.page].image = url;
});
};
}
12 changes: 8 additions & 4 deletions components/ImagePicker/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ export default class ImagePicker extends Component {
if(height > width){
width = height;
}

let imageWidth = width / this.perRow;

return (
<TouchableHighlight onPress={() => {this.onSelect(item)}} key={item.id} underlayColor={item.color}>
<Image
<Image
style={[styles.gallery, {
backgroundColor: item.color,
width: imageWidth,
Expand Down Expand Up @@ -134,10 +134,14 @@ export default class ImagePicker extends Component {
};

onSelect(item){
console.log(item);
this.props.navigator.push({
name: 'ImagePreview', index: this.props.index + 1,
image: item,
callback: this.props.route.callback,
});
}

_onPreviousButton = () => {
this.props.navigator.pop();
};
}
}
5 changes: 5 additions & 0 deletions components/ImagePreview/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "imagepreview",
"private": true,
"main": "view.js"
}
65 changes: 65 additions & 0 deletions components/ImagePreview/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, {
Component,
Text,
Image,
View,
} from 'react-native';
import Button from 'apsl-react-native-button'

export default class ImagePicker extends Component {
render(){
let item = this.props.route.image;
return (
<Image
style={{
backgroundColor: item.color,
flex: 1,
paddingTop: 24+16,
paddingLeft: 16,
}}
source={{uri: item.urls.regular}}
resizeMode="contain">
<Text style={{
color: '#ffffff',
textShadowColor: '#222222',
textShadowOffset: {height: 1, width: 0},
}}>{item.user.name}</Text>
<View style={{
flexDirection: 'row',
width: 200,
position: 'absolute',
right: 16,
top: 24+16,
opacity: 0.8,
}}>
<Button style={{
borderColor: '#2980b9',
backgroundColor: '#3498db',
flex: 1,
marginRight: 10,
}} onPress={this.onUse}>Use</Button>
<Button style={{
borderColor: '#c0392b',
backgroundColor: '#e74c3c',
flex: 1,
}} onPress={() => {
this.props.navigator.pop();
}}>Back</Button>
</View>
</Image>
)
}

onUse = () => {
let routes = this.props.navigator.getCurrentRoutes();

for(let i = routes.length - 1; i >= 0; i--){
let route = routes[i];
if(route.name === 'Editor'){
this.props.route.callback(this.props.route.image.urls.regular);
this.props.navigator.popToRoute(route);
return;
}
}
};
}
Binary file removed components/Slide/bg.jpg
Binary file not shown.
2 changes: 1 addition & 1 deletion components/Slide/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class Slide extends Component {
<Image style={[
styles.image,
size
]} source={this.props.slide.image}>
]} source={{uri: this.props.slide.image}}>
{text}
</Image>
</View>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"apsl-react-native-button": "^2.4.2",
"react": "^0.14.5",
"react-native": "^0.24.1",
"react-native-grid-view": "^0.3.7",
Expand Down

0 comments on commit c72cf32

Please sign in to comment.