1.0.11 • Published 1 year ago

@pachun/simple-expo-update v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

npm version cov

Simple Expo Update

yarn add @pachun/react-native-use-app-lifecycle
yarn add @pachun/simple-expo-update
import useAppLifecycle from "@pachun/react-native-use-app-lifecycle"
import simpleExpoUpdate from "@pachun/simple-expo-update"

const askPermissionToApplyUpdate = async (
  applyUpdateAndRestart: () => Promise<void>,
) => {
  Alert.alert(
    "An app update is available",
    "May we restart the app to apply the update?",
    [
      {
        text: "No",
        style: "cancel",
      },
      {
        text: "Yes",
        onPress: async () => {
          await applyUpdateAndRestart()
        },
      },
    ],
  )
}

const App = () => {
  useAppLifecycle({
    onLaunch: () =>
      simpleExpoUpdate({ whenPresent: "applyUpdate" }),
    onFocus: () =>
      simpleExpoUpdate({ whenPresent: askPermissionToApplyUpdate }),
  })
  return <></>
}

"applyUpdate" applies the update immediately, restarting the app.

You can also pass a function to whenPresent which accepts an argument that's an async function that you can run to apply the update on your own terms.

Jest

"jest": {
  "setupFilesAfterEnv": ["<rootDir>/node_modules/@pachun/simple-expo-update/tests/jest.setup.ts"]
}

Contributing

PRs are exciting 🤟 Bump the version number in package.json and open one.

  • Please do not submit AI generated pull requests.
  • Please keep coverage at or above where it is when you clone the repo (yarn test --collectCoverage).
1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago