Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
razinj committed Oct 22, 2022
2 parents c5224bc + c1bd4cf commit 492e69b
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 87 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ android {
applicationId "com.razinj.context_launcher"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 3
versionName "1.3.0"
versionCode 4
versionName "1.4.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

if (isNewArchitectureEnabled()) {
Expand Down
5 changes: 5 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
env: {
production: {
plugins: ['transform-remove-console'],
},
},
plugins: ['react-native-reanimated/plugin'],
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"babel-jest": "^26.6.3",
"babel-plugin-transform-remove-console": "^6.9.4",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"jest": "^26.6.3",
Expand Down
26 changes: 8 additions & 18 deletions src/components/AllApps.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// React
import React, { MutableRefObject, useMemo, useRef } from 'react'
import React, { MutableRefObject, useRef } from 'react'
// React Native
import { FlatList, ListRenderItem, ListRenderItemInfo, StyleSheet } from 'react-native'
// Components
Expand All @@ -9,21 +9,24 @@ import AllAppsLetterIndex from './AllAppsLetterIndex'
// Redux
import { useSelector } from 'react-redux'
import { selectAppsListMemoized } from '../slices/appsList'
import { selectDisplayAppsIconsMemoized } from '../slices/preferences'
// Reanimated
import { SlideInDown } from 'react-native-reanimated'
// Constants
import { APP_ITEM_HEIGHT_ICON_DISPLAYED, APP_ITEM_HEIGHT_ICON_NOT_DISPLAYED, BACKGROUND_COLOR } from '../constants'
import { APP_ITEM_HEIGHT_ICON_DISPLAYED, BACKGROUND_COLOR } from '../constants'
// Models
import { RenderedIn } from '../models/rendered-in'
import { AppDetails } from '../models/app-details'

const keyExtractor = ({ name }: AppDetails) => name
const getItemLayout = (_data: unknown, index: number) => ({
length: APP_ITEM_HEIGHT_ICON_DISPLAYED,
offset: APP_ITEM_HEIGHT_ICON_DISPLAYED * index,
index,
})

const AllApps = () => {
const apps = useSelector(selectAppsListMemoized)
const listRef: MutableRefObject<FlatList<AppDetails> | null> = useRef(null)
const displayAppsIcons = useSelector(selectDisplayAppsIconsMemoized)

const scrollToIndex = (index: number) => {
const currentListRef = listRef.current as FlatList
Expand All @@ -34,26 +37,13 @@ const AllApps = () => {
<AppItem appDetails={item} renderedIn={RenderedIn.ALL_APPS} />
)

const itemHeight = useMemo(
() => (displayAppsIcons ? APP_ITEM_HEIGHT_ICON_DISPLAYED : APP_ITEM_HEIGHT_ICON_NOT_DISPLAYED),
[displayAppsIcons]
)

const initialNumToRender = useMemo(() => (displayAppsIcons ? 15 : 25), [displayAppsIcons])

const getItemLayout = (_data: unknown, index: number) => ({
length: itemHeight,
offset: itemHeight * index,
index,
})

return (
<CustomView style={styles.wrapper} entryAnimation={SlideInDown}>
<FlatList
data={apps}
ref={listRef}
renderItem={renderItem}
initialNumToRender={initialNumToRender}
initialNumToRender={15}
keyExtractor={keyExtractor}
getItemLayout={getItemLayout}
showsVerticalScrollIndicator={false}
Expand Down
10 changes: 2 additions & 8 deletions src/components/AppItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { Image, Pressable, StyleSheet, View } from 'react-native'
// Components
import HighlightText from './HighlightText'
// Redux
import { useDispatch, useSelector } from 'react-redux'
import { useDispatch } from 'react-redux'
import { addRecentApp } from '../slices/recentApps'
import { resetAppsSearchState } from '../slices/appsSearch'
import { selectDisplayAppsIconsMemoized } from '../slices/preferences'
// Utils
import { launchApp } from '../utils/appsModule'
// Native modules
Expand All @@ -25,7 +24,6 @@ const AppItem = ({ appDetails, renderedIn, appIcon }: Props) => {
const [icon, setIcon] = useState<string | undefined>(undefined)
const { searchAppLaunchProcedure } = useContext(SearchContext)
const { setAppItemMenuDetails, displayAppItemMenuBottomSheet, globalAppLaunchProcedure } = useContext(GlobalContext)
const displayAppsIconsValue = useSelector(selectDisplayAppsIconsMemoized)

const onPress = () => {
// Launch app
Expand All @@ -42,12 +40,8 @@ const AppItem = ({ appDetails, renderedIn, appIcon }: Props) => {
}
}

const displayAppsIcons = useMemo(
() => displayAppsIconsValue || renderedIn === RenderedIn.FAVORITE_APPS,
[displayAppsIconsValue, renderedIn]
)

const displayLabel = useMemo(() => renderedIn !== RenderedIn.FAVORITE_APPS, [renderedIn])
const displayAppsIcons = useMemo(() => renderedIn === RenderedIn.FAVORITE_APPS, [renderedIn])

const onLongPress = () => {
setAppItemMenuDetails({ ...appDetails, icon })
Expand Down
22 changes: 7 additions & 15 deletions src/components/FilteredApps.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
// React
import React, { useContext, useMemo } from 'react'
import React, { useContext } from 'react'
// React Native
import { FlatList, ListRenderItem, ListRenderItemInfo, StyleSheet, Text, View } from 'react-native'
// Components
import AppItem from './AppItem'
// Redux
import { useSelector } from 'react-redux'
import { selectDisplayAppsIconsMemoized } from '../slices/preferences'
import { selectAppsSearchQuery, selectAppsSearchResult } from '../slices/appsSearch'
// Contexts
import SearchContext from '../contexts/SearchContext'
// Constants
import { APP_ITEM_HEIGHT_ICON_DISPLAYED, APP_ITEM_HEIGHT_ICON_NOT_DISPLAYED, BACKGROUND_COLOR } from '../constants'
import { APP_ITEM_HEIGHT_ICON_DISPLAYED, BACKGROUND_COLOR } from '../constants'
// Models
import { RenderedIn } from '../models/rendered-in'
import { AppDetails } from '../models/app-details'

const keyExtractor = ({ name }: AppDetails) => name
const getItemLayout = (_data: unknown, index: number) => ({
length: APP_ITEM_HEIGHT_ICON_DISPLAYED,
offset: APP_ITEM_HEIGHT_ICON_DISPLAYED * index,
index,
})

const FilteredApps = () => {
const apps = useSelector(selectAppsSearchResult)
const { invalidCharacters } = useContext(SearchContext)
const searchQuery = useSelector(selectAppsSearchQuery)
const displayAppsIcons = useSelector(selectDisplayAppsIconsMemoized)

const itemHeight = useMemo(
() => (displayAppsIcons ? APP_ITEM_HEIGHT_ICON_DISPLAYED : APP_ITEM_HEIGHT_ICON_NOT_DISPLAYED),
[displayAppsIcons]
)

if (apps.length === 0 || invalidCharacters) {
return (
Expand All @@ -41,12 +39,6 @@ const FilteredApps = () => {
<AppItem appDetails={item} renderedIn={RenderedIn.FILTERED_APPS} />
)

const getItemLayout = (_data: unknown, index: number) => ({
length: itemHeight,
offset: itemHeight * index,
index,
})

return (
<View style={styles.wrapper}>
<FlatList
Expand Down
22 changes: 7 additions & 15 deletions src/components/RecentApps.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
// React
import React, { useMemo } from 'react'
import React from 'react'
// React Native
import { FlatList, ListRenderItem, ListRenderItemInfo, StyleSheet, Text, View } from 'react-native'
// Redux
import { useSelector } from 'react-redux'
import { selectRecentAppsMemoized } from '../slices/recentApps'
import { selectDisplayAppsIconsMemoized } from '../slices/preferences'
// Components
import AppItem from './AppItem'
// Constants
import { APP_ITEM_HEIGHT_ICON_DISPLAYED, APP_ITEM_HEIGHT_ICON_NOT_DISPLAYED, BACKGROUND_COLOR } from '../constants'
import { APP_ITEM_HEIGHT_ICON_DISPLAYED, BACKGROUND_COLOR } from '../constants'
// Models
import { RenderedIn } from '../models/rendered-in'
import { RecentAppDetails } from '../models/recent-app'

const keyExtractor = ({ name }: RecentAppDetails) => name
const getItemLayout = (_data: unknown, index: number) => ({
length: APP_ITEM_HEIGHT_ICON_DISPLAYED,
offset: APP_ITEM_HEIGHT_ICON_DISPLAYED * index,
index,
})

const RecentApps = () => {
const apps = useSelector(selectRecentAppsMemoized)
const displayAppsIcons = useSelector(selectDisplayAppsIconsMemoized)

const itemHeight = useMemo(
() => (displayAppsIcons ? APP_ITEM_HEIGHT_ICON_DISPLAYED : APP_ITEM_HEIGHT_ICON_NOT_DISPLAYED),
[displayAppsIcons]
)

if (apps.length === 0) {
return (
Expand All @@ -37,12 +35,6 @@ const RecentApps = () => {
<AppItem appDetails={item} appIcon={item.icon} renderedIn={RenderedIn.RECENT_APPS} />
)

const getItemLayout = (_data: unknown, index: number) => ({
length: itemHeight,
offset: itemHeight * index,
index,
})

return (
<View style={styles.wrapper}>
<FlatList
Expand Down
17 changes: 0 additions & 17 deletions src/components/Settings/SettingsBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import SettingsItemLabel from './SettingsItemLabel'
// Redux
import { useDispatch, useSelector } from 'react-redux'
import {
displayAppsIcons,
displayFavoriteApps,
displayRecentApps,
selectDisplayAppsIconsMemoized,
selectDisplayFavoriteAppsMemoized,
selectDisplayRecentAppsMemoized,
} from '../../slices/preferences'
Expand Down Expand Up @@ -54,7 +52,6 @@ const SettingsBottomSheet = () => {
const favoriteAppsCount = useSelector(selectFavoriteAppsCountMemoized)
const displayRecentAppsValue = useSelector(selectDisplayRecentAppsMemoized)
const displayFavoriteAppsValue = useSelector(selectDisplayFavoriteAppsMemoized)
const displayAppsIconsValue = useSelector(selectDisplayAppsIconsMemoized)
const { dismissKeyboard, settingsBottomSheetRef, toggleSortableFavoriteApps } = useContext(GlobalContext)
const [displayAdvancedSettings, setDisplayAdvancedSettings] = useState(false)

Expand All @@ -66,10 +63,6 @@ const SettingsBottomSheet = () => {
dispatch(displayFavoriteApps(!displayFavoriteAppsValue))
}

const toggleDisplayAppsIcons = () => {
dispatch(displayAppsIcons(!displayAppsIconsValue))
}

const onFavoriteAppsSortViewClick = () => {
dismissKeyboard()
toggleSortableFavoriteApps()
Expand Down Expand Up @@ -112,16 +105,6 @@ const SettingsBottomSheet = () => {
</View>

{/* Settings */}
{/* Apps icons switch */}
<View style={styles.itemContainer}>
<SettingsItemLabel title='Display apps icons' />
<Switch
value={displayAppsIconsValue}
onValueChange={toggleDisplayAppsIcons}
trackColor={switchTrackColor}
thumbColor={displayAppsIconsValue ? activeSwitch : inActiveSwitch}
/>
</View>
{/* Recent apps switch */}
<View style={styles.itemContainer}>
<SettingsItemLabel title='Display recent apps' />
Expand Down
1 change: 0 additions & 1 deletion src/constants/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const CONTEXT_LAUNCHER_APP_ID = packageName
export const CONTEXT_LAUNCHER_APP_VERSION = appVersion
export const CONTEXT_LAUNCHER_APP_BUILD_NUMBER = buildNumber
export const APP_ITEM_HEIGHT_ICON_DISPLAYED = 60
export const APP_ITEM_HEIGHT_ICON_NOT_DISPLAYED = 30
// Colors
export const PRIMARY_HEX_COLOR = '#42855B'
export const SECONDARY_HEX_COLOR = '#A0C2AD'
Expand Down
10 changes: 1 addition & 9 deletions src/slices/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import { RootState } from '../store'
export interface PreferencesState {
displayRecentApps: boolean
displayFavoriteApps: boolean
displayAppsIcons: boolean
}

const initialState: PreferencesState = {
displayRecentApps: true,
displayFavoriteApps: true,
displayAppsIcons: true,
}

export const preferencesSlice = createSlice({
Expand All @@ -25,25 +23,19 @@ export const preferencesSlice = createSlice({
displayFavoriteApps: (state: PreferencesState, { payload }: PayloadAction<boolean>) => {
state.displayFavoriteApps = payload
},
displayAppsIcons: (state: PreferencesState, { payload }: PayloadAction<boolean>) => {
state.displayAppsIcons = payload
},
resetPreferences: (state: PreferencesState) => {
state.displayAppsIcons = true
state.displayRecentApps = true
state.displayFavoriteApps = true
},
},
})

export const { displayRecentApps, displayFavoriteApps, displayAppsIcons, resetPreferences } = preferencesSlice.actions
export const { displayRecentApps, displayFavoriteApps, resetPreferences } = preferencesSlice.actions

const selectDisplayRecentApps = (state: RootState) => state.preferences.displayRecentApps
const selectDisplayFavoriteApps = (state: RootState) => state.preferences.displayFavoriteApps
const selectDisplayAppsIcons = (state: RootState) => state.preferences.displayAppsIcons

export const selectDisplayRecentAppsMemoized = createSelector(selectDisplayRecentApps, (value: boolean) => value)
export const selectDisplayFavoriteAppsMemoized = createSelector(selectDisplayFavoriteApps, (value: boolean) => value)
export const selectDisplayAppsIconsMemoized = createSelector(selectDisplayAppsIcons, (value: boolean) => value)

export default preferencesSlice.reducer
Loading

0 comments on commit 492e69b

Please sign in to comment.