Fix photo panel sizing

This commit is contained in:
John Lyon-Smith
2018-04-29 13:32:20 -07:00
parent 16006e933e
commit c403c43c1c
3 changed files with 50 additions and 36 deletions

View File

@@ -3,5 +3,5 @@ import { Route, Redirect } from "react-router-native"
export const DefaultRoute = () => { export const DefaultRoute = () => {
// NOTE: When working on the app, change this to the page you are working on // NOTE: When working on the app, change this to the page you are working on
return <Route render={() => <Redirect to={"/home"} />} /> return <Route render={() => <Redirect to={"/workItem"} />} />
} }

View File

@@ -7,25 +7,25 @@ export const config = {
googleGeocodeAPIKey: "AIzaSyCs4JVT6gysnY5dAJ7KjVJYeykLv_xz1GI", googleGeocodeAPIKey: "AIzaSyCs4JVT6gysnY5dAJ7KjVJYeykLv_xz1GI",
googleGeocodeURL: "https://maps.googleapis.com/maps/api/geocode/json", googleGeocodeURL: "https://maps.googleapis.com/maps/api/geocode/json",
refererURL: "https://dar.kss.us.com", refererURL: "https://dar.kss.us.com",
//defaultUser: "john@lyon-smith.org", defaultUser: "john@lyon-smith.org",
defaultUser: "", // defaultUser: "",
minGPSAccuracy: 100, minGPSAccuracy: 100,
//minGPSAccuracy: 20, //minGPSAccuracy: 20,
minDistanceToItem: 10, minDistanceToItem: 10,
geocodeDelayMilliseconds: 500, geocodeDelayMilliseconds: 500,
// This region is downtown Toronto // This region is downtown Toronto
initialRegion: {
latitude: 43.653908,
longitude: -79.384293,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
},
// This region is Bainbridge Island
// initialRegion: { // initialRegion: {
// latitude: 47.629536, // latitude: 43.653908,
// longitude: -122.524162, // longitude: -79.384293,
// latitudeDelta: 0.0922, // latitudeDelta: 0.0922,
// longitudeDelta: 0.0421, // longitudeDelta: 0.0421,
// }, // },
// This region is Bainbridge Island
initialRegion: {
latitude: 47.629536,
longitude: -122.524162,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
},
alwaysShowWorkItemInAR: true, alwaysShowWorkItemInAR: true,
} }

View File

@@ -23,6 +23,8 @@ const getScreenPortraitDimensions = () => {
} }
} }
const photoSpacing = 10
export class BoundPhotoPanel extends Component { export class BoundPhotoPanel extends Component {
static propTypes = { static propTypes = {
onUploadStarted: PropTypes.func, onUploadStarted: PropTypes.func,
@@ -88,15 +90,25 @@ export class BoundPhotoPanel extends Component {
) )
} }
render() { @autobind
const { screenWidth, screenHeight } = getScreenPortraitDimensions() handleLayout(e) {
const photoWidth = screenHeight / 4 if (!this.state.photoSize) {
const photoHeight = screenWidth / 4 const { layout } = e.nativeEvent
const rowPadding = 10 const { screenWidth, screenHeight } = getScreenPortraitDimensions()
const { value: assetIds } = this.state const ratio = screenWidth / screenHeight
const width = (layout.width - photoSpacing) / 2
const height = width / ratio
const renderPhoto = (index) => { this.setState({ photoSize: { width, height } })
}
}
render() {
const { photoSize, value: assetIds } = this.state
const renderPhoto = (index, size, paddingRight) => {
const assetId = assetIds[index] const assetId = assetIds[index]
const { photoSize } = this.state
if (assetId) { if (assetId) {
console.log(api.makeImageUrl(assetId)) console.log(api.makeImageUrl(assetId))
@@ -106,8 +118,9 @@ export class BoundPhotoPanel extends Component {
<TouchableOpacity <TouchableOpacity
key={assetId || "blank" + index.toString()} key={assetId || "blank" + index.toString()}
style={{ style={{
width: photoWidth, width: size.width,
height: photoHeight, height: size.height,
paddingRight,
borderWidth: 2, borderWidth: 2,
borderColor: "gray", borderColor: "gray",
borderRadius: 4, borderRadius: 4,
@@ -128,18 +141,13 @@ export class BoundPhotoPanel extends Component {
) )
} }
const extraRowStyle = {
height: photoHeight + rowPadding,
paddingTop: rowPadding / 2,
paddingBottom: rowPadding / 2,
}
return ( return (
<View <View
style={{ style={{
flexDirection: "column", flexDirection: "column",
justifyContent: "space-between", justifyContent: "space-between",
}}> }}
onLayout={this.handleLayout}>
<Text <Text
style={{ style={{
fontSize: 14, fontSize: 14,
@@ -147,14 +155,18 @@ export class BoundPhotoPanel extends Component {
}}> }}>
Pictures: Pictures:
</Text> </Text>
<View style={[styles.photoRow, extraRowStyle]}> {photoSize && (
{renderPhoto(0)} <View style={styles.photoRow}>
{renderPhoto(1)} {renderPhoto(0, photoSize, photoSpacing)}
</View> {renderPhoto(1, photoSize)}
<View style={[styles.photoRow, extraRowStyle]}> </View>
{renderPhoto(2)} )}
{renderPhoto(3)} {photoSize && (
</View> <View style={styles.photoRow}>
{renderPhoto(2, photoSize, photoSpacing)}
{renderPhoto(3, photoSize)}
</View>
)}
</View> </View>
) )
} }
@@ -165,5 +177,7 @@ const styles = StyleSheet.create({
flexDirection: "row", flexDirection: "row",
justifyContent: "space-between", justifyContent: "space-between",
width: "100%", width: "100%",
paddingTop: 5,
paddingBottom: 5,
}, },
}) })