base on A Plug & Play Animations for Switching (Dark/Light) Themes. 🌖 # react-native-theme-switch-animation A Plug & Play Animations for Switching (Dark/Light) themes. 🌗 ### 🦄 Features - ✅ Supports multiple animation types. - ✅ Blazing fast - [60/120]fps - ✅ Plug and Play, doesn't matter what you use for switching themes - ✅ Can be used for different theme colors, not necessarily for dark/light - ✅ Supports turbo modules for new architecture <p align="center"> <img src="https://github.com/WadhahEssam/react-native-theme-switch-animation/assets/24798045/0aa19507-702e-4075-b045-303ad27b3dc0" width="600"/> </p> ## Installation ```sh npm install react-native-theme-switch-animation ``` OR ```sh yarn add react-native-theme-switch-animation ``` ## Link (if you are using expo managed project, do a prebuild - `npx expo prebuild`) ``` npx pod-install ``` ## For React Native Versions 0.67 and Below - [follow those instructions](https://github.com/WadhahEssam/react-native-theme-switch-animation/blob/main/installation-for-react-native-below-67.md) ## Usage ```js import switchTheme from 'react-native-theme-switch-animation'; export default function Example() { const [theme, setTheme] = React.useState('light'); return ( <Button title="Switch Theme" onPress={() => { switchTheme({ switchThemeFunction: () => { setTheme(theme === 'light' ? 'dark' : 'light'); // your switch theme function }, animationConfig: { type: 'fade', duration: 900, }, }); }} /> ); } ``` Circular Example ```js switchTheme({ switchThemeFunction: () => { setTheme(theme === 'light' ? 'dark' : 'light'); // your switch theme function }, animationConfig: { type: 'circular', duration: 900, startingPoint: { cxRatio: 0.5, cyRatio: 0.5 } }, }); ``` ## switchTheme Function Props | Name | Type | Description | | :------ | :------ | :------ | | `switchThemeFunction` | `() => void` | Adds the function you use in your app to switch themes, doesn't matter if you use redux/context/zustand/mobx or any other way | | `animationConfig` | `AnimationConfig` | Configuration for the animation -> type, duration, starting point (`default is 'fade' with 500ms duration`) | ## animationConfig options | Name | Type | Description | | :------ | :------ | :------ | | `type` | `fade` `circular` `inverted-circular` | Specifies animation type | | `duration` | `number` | Specifies duration in milliseconds | | `startingPoint` | `StartingPointConfig` | Configuration for the `circular` animation, where does the animation start in the screen | | `captureType` | `layer` or `hierarchy` | (iOS only) `layer` is the default and suitable for most cases, `hierarchy` is more complex and can cause flickering in (inverted-circular) animation, but it solves issue where some elements are not visible while animation is happening | ## startingPoint options | Name | Type | Description | | :------ | :------ | :------ | | `cx` | `number` | Specifies starting x point for `circular` and `inverted-circular` animation (should not exceed your screen width) | | `cy` | `number` | Specifies starting y point for `circular` and `inverted-circular` animation (should not exceed your screen height) | | `cxRatio` | `number` | Specifies starting percentage of x point for `circular` and `inverted-circular` animation (should be number between -1 and 1) | | `cyRatio` | `number` | Specifies starting percentage of y point for `circular` and `inverted-circular` animation (should be number between -1 and 1) | ## Start Circular Animation from/to specific Button If you would like the circular animation to start from/to a button/view on your ui automatically, you can do the following ```js import switchTheme from 'react-native-theme-switch-animation'; <TouchableOpacity onPress={(e) => { e.currentTarget.measure((x1, y1, width, height, px, py) => { switchTheme({ switchThemeFunction: () => { setTheme(theme === 'light' ? 'dark' : 'light'); }, animationConfig: { type: 'circular', duration: 900, startingPoint: { cy: py + height / 2, cx: px + width / 2, } }, }); }); }} /> ``` ## Trouble shooting ### [iOS] Artifact for some components with border https://github.com/WadhahEssam/react-native-theme-switch-animation/assets/24798045/8ad14c41-8757-4c21-b7e7-bf47b23e7f8b this can be solved by adding a borderRadius of any value more than 1.2 for the component ```js <View style={{ borderWidth: 1, borderColor: theme === 'light' ? 'black' : 'white', borderRadius: 1.2, // -> Add This padding: 20, marginBottom: 20, }} > <Text style={{ color: theme === 'light' ? 'black' : 'white', }} > test </Text> </View> ``` ## License MIT ", Assign "at most 3 tags" to the expected json: {"id":"4684","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"