Skip to content

Commit

Permalink
fix(android): prevent ending up scrolled past end
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyers committed Mar 20, 2020
1 parent e1157bb commit 5c14956
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
turtle setup:ios
turtle build:ios --public-url=https://expo.brewedhere.co/ios-index.json --type=simulator --output=brewed-here.tar.gz
- name: Upload ios artifact
if: steps.set_output.outputs.BUILD_APPS == 'true'
uses: actions/upload-artifact@v1
with:
name: ios-archive
Expand Down
19 changes: 14 additions & 5 deletions app/components/BreweryList.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import React, { useRef } from 'react';
import { StyleSheet, FlatList, SafeAreaView } from 'react-native';
import React, { useRef, useState } from 'react';
import { StyleSheet, FlatList, SafeAreaView, Dimensions } from 'react-native';
import BreweryListItem from './BreweryListItem';

export default ({ breweries }) => {
const flatList = useRef(undefined);
const [refresh, setRefresh] = useState(true)

const renderItem = ({ item }) => <BreweryListItem brewery={item} />;
const itemWidth = Dimensions.get('window').width * .8;

return (
<SafeAreaView style={styles.holder}>
<FlatList
ref={flatList}
style={{ height: '100%' }}
data={breweries}
renderItem={({ item }) => <BreweryListItem brewery={item} />}
renderItem={renderItem}
keyExtractor={(item: any) => item.id}
horizontal={true}
showsHorizontalScrollIndicator={false}
onContentSizeChange={() => {
flatList.current.scrollToOffset(0)
getItemLayout={(data, index) => (
{ length: itemWidth, offset: itemWidth * index, index }
)}
// Hack to not end up scrolled past end on Android
onContentSizeChange={(size) => {
setRefresh(!refresh)
}}
extraData={refresh}
/>
</SafeAreaView>
)
Expand Down
2 changes: 0 additions & 2 deletions app/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let dbConn: Promise<Connection>;

export const connect = () => {
if (dbConn == undefined) {
console.log('connect')
dbConn = createConnection({
database: 'db',
driver: require('expo-sqlite'),
Expand All @@ -32,7 +31,6 @@ export const connect = () => {
// })()

export const getAllVisits = async () => {
console.log('getAllVisits')
try {
const db = await dbConn;

Expand Down

0 comments on commit 5c14956

Please sign in to comment.