Refactor state
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import com.facebook.react.ReactActivityDelegate;
|
|||||||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
|
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
|
||||||
import com.facebook.react.defaults.DefaultReactActivityDelegate;
|
import com.facebook.react.defaults.DefaultReactActivityDelegate;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class MainActivity extends ReactActivity {
|
public class MainActivity extends ReactActivity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,6 +18,12 @@ public class MainActivity extends ReactActivity {
|
|||||||
return "Terminally Online";
|
return "Terminally Online";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// react-native-screens override
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
|
* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
|
||||||
* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
|
* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
|
||||||
|
5
index.js
5
index.js
@@ -1,6 +1,9 @@
|
|||||||
import { AppRegistry } from 'react-native';
|
import { AppRegistry } from 'react-native';
|
||||||
|
import 'react-native-get-random-values';
|
||||||
|
import { enableFreeze } from 'react-native-screens';
|
||||||
import App from './src/app';
|
import App from './src/app';
|
||||||
import { name as appName } from './app.json';
|
import { name as appName } from './app.json';
|
||||||
import 'react-native-get-random-values';
|
|
||||||
|
enableFreeze(true);
|
||||||
|
|
||||||
AppRegistry.registerComponent(appName, () => App);
|
AppRegistry.registerComponent(appName, () => App);
|
||||||
|
@@ -10,10 +10,11 @@ import { BottomNavigation, useTheme } from 'react-native-paper';
|
|||||||
import { Home, Tags, Settings, AddMeme, AddTag } from './screens';
|
import { Home, Tags, Settings, AddMeme, AddTag } from './screens';
|
||||||
import { darkNavigationTheme, lightNavigationTheme } from './theme';
|
import { darkNavigationTheme, lightNavigationTheme } from './theme';
|
||||||
import { FloatingActionButton } from './components';
|
import { FloatingActionButton } from './components';
|
||||||
|
import { ROUTE } from './types';
|
||||||
|
|
||||||
const TabNavigator = () => {
|
const TabNavigator = () => {
|
||||||
const [showFab, setShowFab] = React.useState(true);
|
|
||||||
const TabNavigatorBase = createBottomTabNavigator();
|
const TabNavigatorBase = createBottomTabNavigator();
|
||||||
|
const [showFab, setShowFab] = React.useState(true);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -39,7 +40,7 @@ const TabNavigator = () => {
|
|||||||
target: state.key,
|
target: state.key,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setShowFab(route.name !== 'Settings');
|
setShowFab((route.name as ROUTE) !== ROUTE.SETTINGS);
|
||||||
}}
|
}}
|
||||||
renderIcon={({ route, focused, color }) => {
|
renderIcon={({ route, focused, color }) => {
|
||||||
const { options } = descriptors[route.key];
|
const { options } = descriptors[route.key];
|
||||||
@@ -58,7 +59,7 @@ const TabNavigator = () => {
|
|||||||
/>
|
/>
|
||||||
)}>
|
)}>
|
||||||
<TabNavigatorBase.Screen
|
<TabNavigatorBase.Screen
|
||||||
name="Home"
|
name={ROUTE.HOME}
|
||||||
component={Home}
|
component={Home}
|
||||||
options={{
|
options={{
|
||||||
tabBarIcon: ({ color, size }) => (
|
tabBarIcon: ({ color, size }) => (
|
||||||
@@ -67,7 +68,7 @@ const TabNavigator = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<TabNavigatorBase.Screen
|
<TabNavigatorBase.Screen
|
||||||
name="Tags"
|
name={ROUTE.TAGS}
|
||||||
component={Tags}
|
component={Tags}
|
||||||
options={{
|
options={{
|
||||||
tabBarIcon: ({ color, size }) => (
|
tabBarIcon: ({ color, size }) => (
|
||||||
@@ -76,7 +77,7 @@ const TabNavigator = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<TabNavigatorBase.Screen
|
<TabNavigatorBase.Screen
|
||||||
name="Settings"
|
name={ROUTE.SETTINGS}
|
||||||
component={Settings}
|
component={Settings}
|
||||||
options={{
|
options={{
|
||||||
tabBarIcon: ({ color, size }) => (
|
tabBarIcon: ({ color, size }) => (
|
||||||
@@ -97,18 +98,15 @@ const NavigationContainer = () => {
|
|||||||
return (
|
return (
|
||||||
<NavigationContainerBase
|
<NavigationContainerBase
|
||||||
theme={theme.dark ? darkNavigationTheme : lightNavigationTheme}>
|
theme={theme.dark ? darkNavigationTheme : lightNavigationTheme}>
|
||||||
<StackNavigatorBase.Navigator screenOptions={{ headerShown: false }}>
|
<StackNavigatorBase.Navigator
|
||||||
<StackNavigatorBase.Screen name="Main" component={TabNavigator} />
|
screenOptions={{
|
||||||
<StackNavigatorBase.Screen
|
headerShown: false,
|
||||||
name="Add Meme"
|
freezeOnBlur: true,
|
||||||
component={AddMeme}
|
animation: 'slide_from_bottom',
|
||||||
options={{ animation: 'slide_from_bottom' }}
|
}}>
|
||||||
/>
|
<StackNavigatorBase.Screen name={ROUTE.MAIN} component={TabNavigator} />
|
||||||
<StackNavigatorBase.Screen
|
<StackNavigatorBase.Screen name={ROUTE.ADD_MEME} component={AddMeme} />
|
||||||
name="Add Tag"
|
<StackNavigatorBase.Screen name={ROUTE.ADD_TAG} component={AddTag} />
|
||||||
component={AddTag}
|
|
||||||
options={{ animation: 'slide_from_bottom' }}
|
|
||||||
/>
|
|
||||||
</StackNavigatorBase.Navigator>
|
</StackNavigatorBase.Navigator>
|
||||||
</NavigationContainerBase>
|
</NavigationContainerBase>
|
||||||
);
|
);
|
||||||
|
@@ -71,7 +71,7 @@ const Home = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const memes = useQuery<Meme>('Meme');
|
const memes = useQuery<Meme>(Meme.schema.name);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RootScrollView padded>
|
<RootScrollView padded>
|
||||||
|
@@ -60,7 +60,7 @@ const Tags = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const tags = useQuery<Tag>('Tag')
|
const tags = useQuery<Tag>(Tag.schema.name)
|
||||||
.filtered(`name CONTAINS[c] "${search}"`)
|
.filtered(`name CONTAINS[c] "${search}"`)
|
||||||
.sorted(tagSortQuery(sort), sortDirection === SORT_DIRECTION.ASCENDING);
|
.sorted(tagSortQuery(sort), sortDirection === SORT_DIRECTION.ASCENDING);
|
||||||
|
|
||||||
|
@@ -44,6 +44,8 @@ const updateStorageUri = createAsyncThunk(
|
|||||||
const updateNoMedia = createAsyncThunk(
|
const updateNoMedia = createAsyncThunk(
|
||||||
'settings/updateNoMedia',
|
'settings/updateNoMedia',
|
||||||
async (newNoMedia: boolean, { dispatch, getState }) => {
|
async (newNoMedia: boolean, { dispatch, getState }) => {
|
||||||
|
dispatch(setNoMedia(newNoMedia));
|
||||||
|
|
||||||
const state = getState() as RootState;
|
const state = getState() as RootState;
|
||||||
const { storageUri } = state.settings;
|
const { storageUri } = state.settings;
|
||||||
if (!storageUri) return;
|
if (!storageUri) return;
|
||||||
@@ -51,12 +53,12 @@ const updateNoMedia = createAsyncThunk(
|
|||||||
const noMediaExists = await FileSystem.exists(
|
const noMediaExists = await FileSystem.exists(
|
||||||
AndroidScoped.appendPath(storageUri, '.nomedia'),
|
AndroidScoped.appendPath(storageUri, '.nomedia'),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (newNoMedia && !noMediaExists) {
|
if (newNoMedia && !noMediaExists) {
|
||||||
await createFile(storageUri, '.nomedia', 'text/x-unknown');
|
await createFile(storageUri, '.nomedia', 'text/x-unknown');
|
||||||
} else if (!newNoMedia && noMediaExists) {
|
} else if (!newNoMedia && noMediaExists) {
|
||||||
await deleteFile(AndroidScoped.appendPath(storageUri, '.nomedia'));
|
await deleteFile(AndroidScoped.appendPath(storageUri, '.nomedia'));
|
||||||
}
|
}
|
||||||
dispatch(setNoMedia(newNoMedia));
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
export { ROUTE } from './route';
|
||||||
export {
|
export {
|
||||||
HOME_SORT,
|
HOME_SORT,
|
||||||
homeSortQuery,
|
homeSortQuery,
|
||||||
|
9
src/types/route.ts
Normal file
9
src/types/route.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
enum ROUTE {
|
||||||
|
MAIN = 'Main',
|
||||||
|
HOME = 'Home',
|
||||||
|
TAGS = 'Tags',
|
||||||
|
SETTINGS = 'Settings',
|
||||||
|
ADD_MEME = 'Add Meme',
|
||||||
|
ADD_TAG = 'Add Tag',
|
||||||
|
}
|
||||||
|
export { ROUTE };
|
Reference in New Issue
Block a user