-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
17 implement skip this version for android (#18)
* feat: wip * refactor: types * chore: remove default value * refactor: import * chore: update example * chore: wip * chore: wip * chore: wip * ci: enable build ios * chore: update example * ci: disable build:ios
- Loading branch information
Showing
16 changed files
with
200 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 52 additions & 52 deletions
104
example/ios/NeoVersionExample.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { AlertButton } from 'react-native'; | ||
import { startUpdate, presentNextTime, skipThisVersion } from './neoVersion'; | ||
|
||
export const UpdateTypeMap = { | ||
flexible: 0, | ||
immediate: 1, | ||
} as const; | ||
|
||
export type UpdateTypeKey = keyof typeof UpdateTypeMap; | ||
export type UpdateTypeVal = (typeof UpdateTypeMap)[UpdateTypeKey]; | ||
|
||
export const updateButton = (updateType: UpdateTypeKey): AlertButton => { | ||
return { | ||
text: 'Update', | ||
onPress: () => { | ||
startUpdate(updateType); | ||
}, | ||
style: 'default', | ||
}; | ||
}; | ||
|
||
export const skipButton = (): AlertButton => { | ||
return { | ||
text: 'Skip this version', | ||
onPress: () => { | ||
skipThisVersion(); | ||
}, | ||
style: 'default', | ||
}; | ||
}; | ||
|
||
export const nextTimeButton = (day: number): AlertButton => { | ||
return { | ||
text: 'Next Time', | ||
onPress: () => { | ||
presentNextTime(day); | ||
}, | ||
style: 'default', | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { NativeModules } from 'react-native'; | ||
import { UpdateTypeMap, type UpdateTypeKey } from './alertButton'; | ||
|
||
const neoVersion = NativeModules.NeoVersion; | ||
|
||
export function getVersionInfo(): Promise<boolean> { | ||
return neoVersion.getVersionInfo(); | ||
} | ||
|
||
// flexible update by default | ||
export async function startUpdate( | ||
updateType: UpdateTypeKey = 'flexible' | ||
): Promise<void> { | ||
const type = UpdateTypeMap[updateType]; | ||
return await neoVersion.startUpdate(type); | ||
} | ||
|
||
export async function presentNextTime(day: number) { | ||
return await neoVersion.presentNextTime(day); | ||
} | ||
|
||
export async function skipThisVersion(): Promise<void> { | ||
return await neoVersion.skipThisVersion(); | ||
} | ||
|
||
export default neoVersion; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { AlertButton } from 'react-native'; | ||
import { nextTimeButton, skipButton, updateButton } from './alertButton'; | ||
import type { AlertType } from '../types'; | ||
|
||
export const generateAlertButtons = ( | ||
alertType: AlertType, | ||
day: number | ||
): AlertButton[] => { | ||
if (alertType === 'force') return [updateButton('immediate')]; | ||
if (alertType === 'option') | ||
return [updateButton('flexible'), nextTimeButton(day)]; | ||
return [updateButton('flexible'), skipButton(), nextTimeButton(day)]; | ||
}; |
33 changes: 11 additions & 22 deletions
33
src/Android/useNeoVersionCheck.android.ts → src/android/useNeoVersionCheck.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,29 @@ | ||
import { useEffect } from 'react'; | ||
import { | ||
getVersionInfo, | ||
presentNextTime, | ||
startUpdate, | ||
} from './neoVersion.android'; | ||
import { getVersionInfo } from './neoVersion'; | ||
import { Alert } from 'react-native'; | ||
import type { Configuration } from '../types'; | ||
import { generateAlertButtons } from './rules'; | ||
|
||
export const useNeoVersionCheck = (configuration?: Partial<Configuration>) => { | ||
useEffect(() => { | ||
const performVersionCheck = async () => { | ||
const isUpdateAvailable = await getVersionInfo(); | ||
const freq = configuration?.frequency ?? 7; | ||
const type = configuration?.alertType ?? 'skip'; | ||
if (isUpdateAvailable) { | ||
Alert.alert( | ||
configuration?.title ?? 'Update Available', | ||
configuration?.message ?? | ||
'Please update the app to have the best experience', | ||
[ | ||
{ | ||
text: 'Update', | ||
onPress: () => { | ||
startUpdate(); | ||
}, | ||
style: 'default', | ||
}, | ||
{ | ||
text: 'Next time', | ||
onPress: () => { | ||
presentNextTime(configuration?.frequency ?? 7); | ||
}, | ||
style: 'default', | ||
}, | ||
] | ||
generateAlertButtons(type, freq) | ||
); | ||
} | ||
}; | ||
performVersionCheck(); | ||
}, [configuration?.frequency, configuration?.message, configuration?.title]); | ||
}, [ | ||
configuration?.alertType, | ||
configuration?.frequency, | ||
configuration?.message, | ||
configuration?.title, | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { useNeoVersionCheck } from './Android/useNeoVersionCheck.android'; | ||
export { useNeoVersionCheck } from './android/useNeoVersionCheck'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { useNeoVersionCheck } from './iOS/useNeoVersionCheck.ios'; | ||
export { useNeoVersionCheck } from './ios/useNeoVersionCheck'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters