@amazon-devices/expo-linear-gradient 2.0.1758683737

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/.eslintrc.js +2 -0
  2. package/CHANGELOG.md +209 -0
  3. package/CMakeLists.txt +52 -0
  4. package/LICENSE +7 -0
  5. package/README.kepler.md +69 -0
  6. package/README.md +41 -0
  7. package/THIRD_PARTY_NOTICES.txt +24 -0
  8. package/android/build.gradle +107 -0
  9. package/android/src/main/AndroidManifest.xml +3 -0
  10. package/android/src/main/java/expo/modules/lineargradient/LinearGradientModule.kt +36 -0
  11. package/android/src/main/java/expo/modules/lineargradient/LinearGradientView.java +117 -0
  12. package/build/LinearGradient.d.ts +60 -0
  13. package/build/LinearGradient.d.ts.map +1 -0
  14. package/build/LinearGradient.js +31 -0
  15. package/build/LinearGradient.js.map +1 -0
  16. package/build/NativeLinearGradient.android.d.ts +4 -0
  17. package/build/NativeLinearGradient.android.d.ts.map +1 -0
  18. package/build/NativeLinearGradient.android.js +27 -0
  19. package/build/NativeLinearGradient.android.js.map +1 -0
  20. package/build/NativeLinearGradient.d.ts +4 -0
  21. package/build/NativeLinearGradient.d.ts.map +1 -0
  22. package/build/NativeLinearGradient.ios.d.ts +5 -0
  23. package/build/NativeLinearGradient.ios.d.ts.map +1 -0
  24. package/build/NativeLinearGradient.ios.js +4 -0
  25. package/build/NativeLinearGradient.ios.js.map +1 -0
  26. package/build/NativeLinearGradient.js +10 -0
  27. package/build/NativeLinearGradient.js.map +1 -0
  28. package/build/NativeLinearGradient.kepler.d.ts +23 -0
  29. package/build/NativeLinearGradient.kepler.d.ts.map +1 -0
  30. package/build/NativeLinearGradient.kepler.js +23 -0
  31. package/build/NativeLinearGradient.kepler.js.map +1 -0
  32. package/build/NativeLinearGradient.types.d.ts +11 -0
  33. package/build/NativeLinearGradient.types.d.ts.map +1 -0
  34. package/build/NativeLinearGradient.types.js +2 -0
  35. package/build/NativeLinearGradient.types.js.map +1 -0
  36. package/build/NativeLinearGradient.web.d.ts +8 -0
  37. package/build/NativeLinearGradient.web.d.ts.map +1 -0
  38. package/build/NativeLinearGradient.web.js +79 -0
  39. package/build/NativeLinearGradient.web.js.map +1 -0
  40. package/build/normalizeColor.d.ts +2 -0
  41. package/build/normalizeColor.d.ts.map +1 -0
  42. package/build/normalizeColor.js +29 -0
  43. package/build/normalizeColor.js.map +1 -0
  44. package/expo-module.config.json +10 -0
  45. package/ios/ExpoLinearGradient.podspec +32 -0
  46. package/ios/LinearGradientLayer.swift +107 -0
  47. package/ios/LinearGradientModule.swift +28 -0
  48. package/ios/LinearGradientView.swift +14 -0
  49. package/kepler/ExpoLinearGradientDrawableLayer.cpp +85 -0
  50. package/kepler/ExpoLinearGradientDrawableLayer.h +81 -0
  51. package/kepler/ExpoLinearGradientView.cpp +92 -0
  52. package/kepler/ExpoLinearGradientView.h +37 -0
  53. package/kepler/ExpoLinearGradientViewManager.cpp +28 -0
  54. package/kepler/ExpoLinearGradientViewManager.h +19 -0
  55. package/kepler/KeplerInit.cpp +28 -0
  56. package/kepler/test/ExpoLinearGradientDrawableLayer.cpp +134 -0
  57. package/kepler/test/ExpoLinearGradientView.cpp +86 -0
  58. package/kepler/test/ExpoLinearGradientViewManager.cpp +37 -0
  59. package/package.json +1 -0
  60. package/react-native.config.js +21 -0
  61. package/src/LinearGradient.tsx +103 -0
  62. package/src/NativeLinearGradient.android.tsx +49 -0
  63. package/src/NativeLinearGradient.ios.tsx +10 -0
  64. package/src/NativeLinearGradient.kepler.tsx +36 -0
  65. package/src/NativeLinearGradient.tsx +12 -0
  66. package/src/NativeLinearGradient.types.ts +21 -0
  67. package/src/NativeLinearGradient.web.tsx +115 -0
  68. package/src/normalizeColor.ts +32 -0
  69. package/tsconfig.json +9 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,2 @@
1
+ // @generated by expo-module-scripts
2
+ module.exports = require('expo-module-scripts/eslintrc.base.js');
package/CHANGELOG.md ADDED
@@ -0,0 +1,209 @@
1
+ # Changelog
2
+
3
+ ## Unpublished
4
+
5
+ ### 🛠 Breaking changes
6
+
7
+ ### 🎉 New features
8
+
9
+ ### 🐛 Bug fixes
10
+
11
+ ### 💡 Others
12
+
13
+ ## 12.6.0 — 2023-10-17
14
+
15
+ ### 🛠 Breaking changes
16
+
17
+ - Dropped support for Android SDK 21 and 22. ([#24201](https://github.com/expo/expo/pull/24201) by [@behenate](https://github.com/behenate))
18
+
19
+ ### 💡 Others
20
+
21
+ - Ship untranspiled JSX to support custom handling of `jsx` and `createElement`. ([#24889](https://github.com/expo/expo/pull/24889) by [@EvanBacon](https://github.com/EvanBacon))
22
+
23
+ ## 12.5.0 — 2023-09-04
24
+
25
+ ### 🎉 New features
26
+
27
+ - Added support for React Native 0.73. ([#24018](https://github.com/expo/expo/pull/24018) by [@kudo](https://github.com/kudo))
28
+
29
+ ## 12.4.0 — 2023-08-02
30
+
31
+ _This version does not introduce any user-facing changes._
32
+
33
+ ## 12.3.0 — 2023-06-21
34
+
35
+ ### 🐛 Bug fixes
36
+
37
+ - Fixed Android build warnings for Gradle version 8. ([#22537](https://github.com/expo/expo/pull/22537), [#22609](https://github.com/expo/expo/pull/22609) by [@kudo](https://github.com/kudo))
38
+
39
+ ## 12.2.0 — 2023-05-08
40
+
41
+ _This version does not introduce any user-facing changes._
42
+
43
+ ## 12.1.2 - 2023-03-08
44
+
45
+ ### 🐛 Bug fixes
46
+
47
+ - Fixed crashes when R8 or Proguard is enabled. ([#21580](https://github.com/expo/expo/pull/21580) by [@kudo](https://github.com/kudo))
48
+
49
+ ## 12.1.1 — 2023-02-09
50
+
51
+ _This version does not introduce any user-facing changes._
52
+
53
+ ## 12.1.0 — 2023-02-03
54
+
55
+ ### 💡 Others
56
+
57
+ - On Android bump `compileSdkVersion` and `targetSdkVersion` to `33`. ([#20721](https://github.com/expo/expo/pull/20721) by [@lukmccall](https://github.com/lukmccall))
58
+
59
+ ## 12.0.1 — 2022-11-02
60
+
61
+ _This version does not introduce any user-facing changes._
62
+
63
+ ## 12.0.0 — 2022-10-25
64
+
65
+ ### 🐛 Bug fixes
66
+
67
+ - Fix default start and end points on Android. ([#19460](https://github.com/expo/expo/pull/19460) by [@tsapeta](https://github.com/tsapeta))
68
+
69
+ ## 12.0.0-beta.1 — 2022-10-06
70
+
71
+ ### 🛠 Breaking changes
72
+
73
+ - Bumped iOS deployment target to 13.0 and deprecated support for iOS 12. ([#18873](https://github.com/expo/expo/pull/18873) by [@tsapeta](https://github.com/tsapeta))
74
+
75
+ ## 11.4.0 — 2022-07-07
76
+
77
+ ### 💡 Others
78
+
79
+ - Migrated Expo modules definitions to the new naming convention. ([#17193](https://github.com/expo/expo/pull/17193) by [@tsapeta](https://github.com/tsapeta))
80
+
81
+ ## 11.3.0 — 2022-04-18
82
+
83
+ ### 🐛 Bug fixes
84
+
85
+ - Extract `react-native-web` internals into package to minimize bundler setup. ([#16098](https://github.com/expo/expo/pull/16098) by [@EvanBacon](https://github.com/EvanBacon))
86
+ - Fix `Plugin with id 'maven' not found` build error from Android Gradle 7. ([#16080](https://github.com/expo/expo/pull/16080) by [@kudo](https://github.com/kudo))
87
+ - Fixed the component not rendering correctly when the border radius style is set. ([#16671](https://github.com/expo/expo/pull/16671) by [@tsapeta](https://github.com/tsapeta))
88
+
89
+ ### ⚠️ Notices
90
+
91
+ - On Android bump `compileSdkVersion` to `31`, `targetSdkVersion` to `31` and `Java` version to `11`. ([#16941](https://github.com/expo/expo/pull/16941) by [@bbarthec](https://github.com/bbarthec))
92
+
93
+ ## 11.2.0 — 2022-01-26
94
+
95
+ ### 🐛 Bug fixes
96
+
97
+ - Fix display issue on iOS when more than 2 colors are used without explicit locations. ([#15955](https://github.com/expo/expo/pull/15955) by [@kbrandwijk](https://github.com/kbrandwijk))
98
+
99
+ ## 11.1.0 — 2022-01-26
100
+
101
+ ### 🐛 Bug fixes
102
+
103
+ - Prevent crashes by adding unimplemented `CALayer` initializer `init(layer:)`. ([#15843](https://github.com/expo/expo/pull/15843) by [@dillonhafer](https://github.com/dillonhafer))
104
+
105
+ ## 11.0.3 — 2022-02-06
106
+
107
+ ### 🐛 Bug fixes
108
+
109
+ - Prevent crashes by adding unimplemented `CALayer` initializer `init(layer:)`. ([#15843](https://github.com/expo/expo/pull/15843) by [@dillonhafer](https://github.com/dillonhafer))
110
+
111
+ ## 11.0.2 — 2022-02-01
112
+
113
+ ### 🐛 Bug fixes
114
+
115
+ - Fix `Plugin with id 'maven' not found` build error from Android Gradle 7. ([#16080](https://github.com/expo/expo/pull/16080) by [@kudo](https://github.com/kudo))
116
+
117
+ ## 11.0.1 — 2022-01-27
118
+
119
+ ### 🐛 Bug fixes
120
+
121
+ - Fix display issue on iOS when more than 2 colors are used without explicit locations. ([#15955](https://github.com/expo/expo/pull/15955) by [@kbrandwijk](https://github.com/kbrandwijk))
122
+
123
+ ## 11.0.0 — 2021-12-03
124
+
125
+ ### 💡 Others
126
+
127
+ - Rewrote code to Swift, removed legacy Objective-C module implementation and changed the pod name to `ExpoLinearGradient`. ([#15168](https://github.com/expo/expo/pull/15168) by [@tsapeta](https://github.com/tsapeta))
128
+ - Rewrote module using Sweet API on Android. ([#15166](https://github.com/expo/expo/pull/15166) by [@lukmccall](https://github.com/lukmccall))
129
+
130
+ ## 10.0.1 — 2021-10-01
131
+
132
+ _This version does not introduce any user-facing changes._
133
+
134
+ ## 10.0.0 — 2021-09-28
135
+
136
+ ### 🛠 Breaking changes
137
+
138
+ - Dropped support for iOS 11.0 ([#14383](https://github.com/expo/expo/pull/14383) by [@cruzach](https://github.com/cruzach))
139
+
140
+ ### 🐛 Bug fixes
141
+
142
+ - Fix building errors from use_frameworks! in Podfile. ([#14523](https://github.com/expo/expo/pull/14523) by [@kudo](https://github.com/kudo))
143
+
144
+ ## 9.3.0-alpha.0 — 2021-08-17
145
+
146
+ ### 💡 Others
147
+
148
+ - Migrated from `@unimodules/core` to `expo-modules-core`. (by [@tsapeta](https://github.com/tsapeta))
149
+ - Experimental Swift implementation using Sweet API. (by [@tsapeta](https://github.com/tsapeta))
150
+
151
+ ## 9.2.0 — 2021-06-16
152
+
153
+ ### 🐛 Bug fixes
154
+
155
+ - Enable kotlin in all modules. ([#12716](https://github.com/expo/expo/pull/12716) by [@wschurman](https://github.com/wschurman))
156
+
157
+ ### 💡 Others
158
+
159
+ - Build Android code using Java 8 to fix Android instrumented test build error. ([#12939](https://github.com/expo/expo/pull/12939) by [@kudo](https://github.com/kudo))
160
+
161
+ ## 9.1.0 — 2021-03-10
162
+
163
+ ### 🎉 New features
164
+
165
+ - Updated Android build configuration to target Android 11 (added support for Android SDK 30). ([#11647](https://github.com/expo/expo/pull/11647) by [@bbarthec](https://github.com/bbarthec))
166
+
167
+ ### 🐛 Bug fixes
168
+
169
+ - Remove peerDependencies and unimodulePeerDependencies from Expo modules. ([#11980](https://github.com/expo/expo/pull/11980) by [@brentvatne](https://github.com/brentvatne))
170
+
171
+ ## 9.0.0 — 2021-01-15
172
+
173
+ ### 🛠 Breaking changes
174
+
175
+ - Dropped support for iOS 10.0 ([#11344](https://github.com/expo/expo/pull/11344) by [@tsapeta](https://github.com/tsapeta))
176
+
177
+ ## 8.4.0 — 2020-11-25
178
+
179
+ ### 🐛 Bug fixes
180
+
181
+ - Revert to class component. ([#11111](https://github.com/expo/expo/pull/11111) by [@EvanBacon](https://github.com/EvanBacon))
182
+
183
+ ## 8.3.1 — 2020-09-23
184
+
185
+ ### 🐛 Bug fixes
186
+
187
+ - Added `children` property to `LinearGradient` component ([#10227](https://github.com/expo/expo/pull/10227) by [@sjchmiela](https://github.com/sjchmiela))
188
+
189
+ ## 8.3.0 — 2020-08-18
190
+
191
+ _This version does not introduce any user-facing changes._
192
+
193
+ ## 8.2.2 — 2020-07-29
194
+
195
+ ### 🎉 New features
196
+
197
+ - Remove `prop-types` ([#8681](https://github.com/expo/expo/pull/8681) by [@EvanBacon](https://github.com/EvanBacon))
198
+
199
+ ### 🐛 Bug fixes
200
+
201
+ - Renamed type export `LinearGradienPoint` to `LinearGradientPoint`. ([#8673](https://github.com/expo/expo/pull/8673) by [@EvanBacon](https://github.com/EvanBacon))
202
+
203
+ ## 8.2.1 — 2020-05-29
204
+
205
+ _This version does not introduce any user-facing changes._
206
+
207
+ ## 8.2.0 — 2020-05-27
208
+
209
+ _This version does not introduce any user-facing changes._
package/CMakeLists.txt ADDED
@@ -0,0 +1,52 @@
1
+ #
2
+ # Copyright 2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3
+ #
4
+ # AMAZON PROPRIETARY/CONFIDENTIAL
5
+ #
6
+ # You may not use this file except in compliance with the terms and conditions
7
+ # set forth in the accompanying LICENSE.TXT file.
8
+ #
9
+ # THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
10
+ # DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
11
+ # IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
12
+ # FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
13
+ #
14
+ set(PACKAGE_NAME "expo-linear-gradient")
15
+ set(AUTO_LINK_PACKAGE_NAME "${PACKAGE_NAME}-${KEPLER_REACT_NATIVE_MAJOR_VERSION}")
16
+ set(SOURCES_KEPLER
17
+ kepler/ExpoLinearGradientDrawableLayer.cpp
18
+ kepler/ExpoLinearGradientView.cpp
19
+ kepler/ExpoLinearGradientViewManager.cpp
20
+ )
21
+
22
+ set(KEPLER_INIT kepler/KeplerInit.cpp)
23
+
24
+ add_library(${PACKAGE_NAME} STATIC ${SOURCES_KEPLER})
25
+
26
+ target_link_libraries(
27
+ ${PACKAGE_NAME}
28
+ PUBLIC
29
+ keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
30
+ )
31
+
32
+ add_library(${AUTO_LINK_PACKAGE_NAME} SHARED ${KEPLER_INIT} ${SOURCES_KEPLER})
33
+
34
+ set_target_properties(${AUTO_LINK_PACKAGE_NAME} PROPERTIES SOVERSION ${KEPLER_REACT_NATIVE_MAJOR_VERSION}.${KEPLER_REACT_NATIVE_MINOR_VERSION})
35
+
36
+ target_link_libraries(
37
+ ${AUTO_LINK_PACKAGE_NAME}
38
+ PRIVATE
39
+ ${PACKAGE_NAME}
40
+ )
41
+
42
+ # Helps in checking undefined references
43
+ add_executable(${AUTO_LINK_PACKAGE_NAME}_exe ${KEPLER_INIT} ${SOURCES_KEPLER})
44
+ target_link_libraries(${AUTO_LINK_PACKAGE_NAME}_exe
45
+ PRIVATE
46
+ ${AUTO_LINK_PACKAGE_NAME}
47
+ keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
48
+ )
49
+
50
+ install(TARGETS ${AUTO_LINK_PACKAGE_NAME}
51
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
52
+ )
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
2
+
3
+ These materials are licensed as "Program Materials" under the Program Materials License Agreement (the "Agreement"). The Agreement is available at https://developer.amazon.com/support/legal/pml. See the Agreement for the specific terms and conditions of the Agreement. Capitalized terms not defined in this file have the meanings given to them in the Agreement.
4
+
5
+ If you do not agree to the above terms and conditions, you may not use any file in this package.
6
+
7
+ YOUR USE OF THE PROGRAM MATERIALS IN OR ASSOCIATED WITH THIS PACKAGE IS AT YOUR SOLE RISK. IN NO EVENT WILL AMAZON BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL, INCIDENTAL, OR PUNITIVE DAMAGES (INCLUDING FOR ANY LOSS OF GOODWILL, BUSINESS INTERRUPTION, LOST PROFITS OR DATA, OR COMPUTER FAILURE OR MALFUNCTION) ARISING FROM OR RELATING TO SUCH PROGRAM MATERIALS, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, EVEN IF AMAZON HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS AND DISCLAIMERS APPLY EXCEPT TO THE EXTENT PROHIBITED BY APPLICABLE LAW.
@@ -0,0 +1,69 @@
1
+ # @amazon-devices/expo-linear-gradient
2
+
3
+ ## Getting Started
4
+
5
+ `@amazon-devices/expo-linear-gradient` provides a native React view that transitions between multiple colors in a linear direction.
6
+
7
+ ### Installation
8
+
9
+ 1. Add the JavaScript library dependency in the `package.json` file:
10
+ ```json
11
+ dependencies: {
12
+ ...
13
+ "@amazon-devices/expo-linear-gradient": "~2.0.0",
14
+ }
15
+ ```
16
+
17
+ 2. Reinstall dependencies using `npm install` command.
18
+
19
+ ## Usage Examples
20
+
21
+ ```js
22
+ import React from 'react';
23
+ import {LinearGradient} from '@amazon-devices/expo-linear-gradient';
24
+
25
+ export const App = () => {
26
+ return (
27
+ <LinearGradient
28
+ colors={['white', 'red']}
29
+ start={[0.5, 0.5]}
30
+ end={[1, 1]}
31
+ style={{
32
+ width: 100,
33
+ maxHeight: 200,
34
+ minHeight: 200,
35
+ borderWidth: 1,
36
+ marginVertical: 20,
37
+ borderColor: 'black',
38
+ }}
39
+ />
40
+ );
41
+ };
42
+
43
+
44
+ ```
45
+
46
+ ## API Reference
47
+
48
+ Check out the dedicated documentation page for info about this library, API reference and more: [Official Expo documentation for expo-linear-gradient](https://github.com/expo/expo/blob/sdk-49/docs/pages/versions/v49.0.0/sdk/linear-gradient.mdx).
49
+
50
+ ### Components
51
+
52
+ | Component | Description | Platform support |
53
+ |---------- | ----------- | ---------------- |
54
+ | LinearGradient | Renders a native view that transitions between multiple colors in a linear direction | All |
55
+
56
+ #### LinearGradient Props
57
+
58
+ | Prop | Description | Platform support |
59
+ | ---- | ----------- | ---------------- |
60
+ | colors | An array of colors that represent stops in the gradient. At least two colors are required (for a single-color background, use the `style.backgroundColor` prop on a `View` component) | All |
61
+ | start | For example, { x: 0.1, y: 0.2 } means that the gradient will start 10% from the left and 20% from the top | All |
62
+ | end | For example, { x: 0.1, y: 0.2 } means that the gradient will end 10% from the left and 20% from the bottom | All |
63
+ | locations | An array that contains numbers ranging from 0 to 1, inclusive, and is the same length as the colors property. Each number indicates a color-stop location where each respective color should be located. If not specified, the colors will be distributed evenly across the gradient | All |
64
+
65
+ ## Supported Versions
66
+
67
+ | Package version | Based on | @amazon-devices/react-native-kepler version |
68
+ | ---------------- | -------- | --------------------------------- |
69
+ | 2.0.x | expo-linear-gradient v12.6.0 | 2.0.x |
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ <p>
2
+ <a href="https://docs.expo.dev/versions/latest/sdk/linear-gradient/">
3
+ <img
4
+ src="../../.github/resources/expo-linear-gradient.svg"
5
+ alt="expo-linear-gradient"
6
+ height="64" />
7
+ </a>
8
+ </p>
9
+
10
+ Provides a React component that renders a gradient view.
11
+
12
+ # API documentation
13
+
14
+ - [Documentation for the main branch](https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/linear-gradient.mdx)
15
+ - [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/linear-gradient/)
16
+
17
+ # Installation in managed Expo projects
18
+
19
+ For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/linear-gradient/).
20
+
21
+ # Installation in bare React Native projects
22
+
23
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
24
+
25
+ ### Add the package to your npm dependencies
26
+
27
+ ```
28
+ npx expo install expo-linear-gradient
29
+ ```
30
+
31
+ ### Configure for iOS
32
+
33
+ Run `npx pod-install` after installing the npm package.
34
+
35
+ ### Configure for Android
36
+
37
+ No additional set up necessary.
38
+
39
+ # Contributing
40
+
41
+ Contributions are very welcome! Please refer to guidelines described in the [contributing guide](https://github.com/expo/expo#contributing).
@@ -0,0 +1,24 @@
1
+ License from package.json:
2
+ ==============================
3
+
4
+ The MIT License (MIT)
5
+
6
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
@@ -0,0 +1,107 @@
1
+ apply plugin: 'com.android.library'
2
+ apply plugin: 'kotlin-android'
3
+ apply plugin: 'maven-publish'
4
+
5
+ group = 'host.exp.exponent'
6
+ version = '12.6.0'
7
+
8
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
9
+ if (expoModulesCorePlugin.exists()) {
10
+ apply from: expoModulesCorePlugin
11
+ applyKotlinExpoModulesCorePlugin()
12
+ // Remove this check, but keep the contents after SDK49 support is dropped
13
+ if (safeExtGet("expoProvidesDefaultConfig", false)) {
14
+ useExpoPublishing()
15
+ useCoreDependencies()
16
+ }
17
+ }
18
+
19
+ buildscript {
20
+ // Simple helper that allows the root project to override versions declared by this library.
21
+ ext.safeExtGet = { prop, fallback ->
22
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
23
+ }
24
+
25
+ // Ensures backward compatibility
26
+ ext.getKotlinVersion = {
27
+ if (ext.has("kotlinVersion")) {
28
+ ext.kotlinVersion()
29
+ } else {
30
+ ext.safeExtGet("kotlinVersion", "1.8.10")
31
+ }
32
+ }
33
+
34
+ repositories {
35
+ mavenCentral()
36
+ }
37
+
38
+ dependencies {
39
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
40
+ }
41
+ }
42
+
43
+ // Remove this if and it's contents, when support for SDK49 is dropped
44
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
45
+ afterEvaluate {
46
+ publishing {
47
+ publications {
48
+ release(MavenPublication) {
49
+ from components.release
50
+ }
51
+ }
52
+ repositories {
53
+ maven {
54
+ url = mavenLocal().url
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ android {
62
+ // Remove this if and it's contents, when support for SDK49 is dropped
63
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
64
+ compileSdkVersion safeExtGet("compileSdkVersion", 33)
65
+
66
+ defaultConfig {
67
+ minSdkVersion safeExtGet("minSdkVersion", 23)
68
+ targetSdkVersion safeExtGet("targetSdkVersion", 33)
69
+ }
70
+
71
+ publishing {
72
+ singleVariant("release") {
73
+ withSourcesJar()
74
+ }
75
+ }
76
+
77
+ lintOptions {
78
+ abortOnError false
79
+ }
80
+ }
81
+
82
+ def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
83
+ if (agpVersion.tokenize('.')[0].toInteger() < 8) {
84
+ compileOptions {
85
+ sourceCompatibility JavaVersion.VERSION_11
86
+ targetCompatibility JavaVersion.VERSION_11
87
+ }
88
+
89
+ kotlinOptions {
90
+ jvmTarget = JavaVersion.VERSION_11.majorVersion
91
+ }
92
+ }
93
+
94
+ namespace "expo.modules.lineargradient"
95
+ defaultConfig {
96
+ versionCode 17
97
+ versionName "12.6.0"
98
+ }
99
+ }
100
+
101
+ dependencies {
102
+ // Remove this if and it's contents, when support for SDK49 is dropped
103
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
104
+ implementation project(':expo-modules-core')
105
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
106
+ }
107
+ }
@@ -0,0 +1,3 @@
1
+ <manifest>
2
+
3
+ </manifest>
@@ -0,0 +1,36 @@
1
+ package expo.modules.lineargradient
2
+
3
+ import expo.modules.kotlin.modules.Module
4
+ import expo.modules.kotlin.modules.ModuleDefinition
5
+
6
+ typealias ViewType = LinearGradientView
7
+
8
+ class LinearGradientModule : Module() {
9
+ override fun definition() = ModuleDefinition {
10
+ Name("ExpoLinearGradient")
11
+
12
+ View(LinearGradientView::class) {
13
+ Prop("colors") { view: ViewType, colors: IntArray ->
14
+ view.setColors(colors)
15
+ }
16
+
17
+ Prop("locations") { view: ViewType, locations: FloatArray? ->
18
+ locations?.let {
19
+ view.setLocations(it)
20
+ }
21
+ }
22
+
23
+ Prop("startPoint") { view: ViewType, startPoint: Pair<Float, Float>? ->
24
+ view.setStartPosition(startPoint?.first ?: 0.5f, startPoint?.second ?: 0f)
25
+ }
26
+
27
+ Prop("endPoint") { view: ViewType, endPoint: Pair<Float, Float>? ->
28
+ view.setEndPosition(endPoint?.first ?: 0.5f, endPoint?.second ?: 1f)
29
+ }
30
+
31
+ Prop("borderRadii") { view: ViewType, borderRadii: FloatArray? ->
32
+ view.setBorderRadii(borderRadii ?: FloatArray(8) { 0f })
33
+ }
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,117 @@
1
+ package expo.modules.lineargradient;
2
+
3
+ import android.content.Context;
4
+ import android.graphics.Canvas;
5
+ import android.graphics.LinearGradient;
6
+ import android.graphics.Paint;
7
+ import android.graphics.Path;
8
+ import android.graphics.RectF;
9
+ import android.graphics.Shader;
10
+ import android.util.TypedValue;
11
+ import android.view.View;
12
+ import expo.modules.core.interfaces.DoNotStrip;
13
+
14
+ public class LinearGradientView extends View {
15
+ private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
16
+ private Path mPathForBorderRadius;
17
+ private RectF mTempRectForBorderRadius;
18
+
19
+ private float[] mLocations;
20
+ private float[] mStartPos = {0.5F, 0};
21
+ private float[] mEndPos = {0.5F, 1};
22
+ private int[] mColors;
23
+ private int[] mSize = {0, 0};
24
+ private float[] mBorderRadii = {0, 0, 0, 0, 0, 0, 0, 0};
25
+
26
+ // Keeps this primary constructor from Proguard/R8 for ViewDefinitionBuilder
27
+ @DoNotStrip
28
+ public LinearGradientView(Context context) {
29
+ super(context);
30
+ }
31
+
32
+ public void setStartPosition(final float x, final float y) {
33
+ mStartPos = new float[]{x, y};
34
+ drawGradient();
35
+ }
36
+
37
+ public void setEndPosition(final float x, final float y) {
38
+ mEndPos = new float[]{x, y};
39
+ drawGradient();
40
+ }
41
+
42
+ public void setColors(final int[] colors) {
43
+ mColors = colors;
44
+ drawGradient();
45
+ }
46
+
47
+ public void setLocations(final float[] locations) {
48
+ mLocations = locations;
49
+ drawGradient();
50
+ }
51
+
52
+ public void setBorderRadii(final float[] borderRadii) {
53
+ for (int i = 0; i < borderRadii.length; i++) {
54
+ borderRadii[i] = toPixelFromDIP(borderRadii[i]);
55
+ }
56
+ mBorderRadii = borderRadii;
57
+ updatePath();
58
+ drawGradient();
59
+ }
60
+
61
+ // Copied from RN PixelUtil
62
+ // We might want to expose display metrics on @unimodules/core somewhere to avoid
63
+ // having code similar to this littered throughout modules
64
+ private float toPixelFromDIP(float value) {
65
+ return TypedValue.applyDimension(
66
+ TypedValue.COMPLEX_UNIT_DIP,
67
+ value,
68
+ getContext().getResources().getDisplayMetrics()
69
+ );
70
+ }
71
+
72
+ @Override
73
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
74
+ mSize = new int[]{w, h};
75
+ updatePath();
76
+ drawGradient();
77
+ }
78
+
79
+ private void drawGradient() {
80
+ // guard against crashes happening while multiple properties are updated
81
+ if (mColors == null || (mLocations != null && mColors.length != mLocations.length))
82
+ return;
83
+ LinearGradient mShader = new LinearGradient(
84
+ mStartPos[0] * mSize[0],
85
+ mStartPos[1] * mSize[1],
86
+ mEndPos[0] * mSize[0],
87
+ mEndPos[1] * mSize[1],
88
+ mColors,
89
+ mLocations,
90
+ Shader.TileMode.CLAMP);
91
+ mPaint.setShader(mShader);
92
+ invalidate();
93
+ }
94
+
95
+ private void updatePath() {
96
+ if (mPathForBorderRadius == null) {
97
+ mPathForBorderRadius = new Path();
98
+ mTempRectForBorderRadius = new RectF();
99
+ }
100
+ mPathForBorderRadius.reset();
101
+ mTempRectForBorderRadius.set(0f, 0f, (float) mSize[0], (float) mSize[1]);
102
+ mPathForBorderRadius.addRoundRect(
103
+ mTempRectForBorderRadius,
104
+ mBorderRadii,
105
+ Path.Direction.CW);
106
+ }
107
+
108
+ @Override
109
+ protected void onDraw(Canvas canvas) {
110
+ super.onDraw(canvas);
111
+ if (mPathForBorderRadius == null) {
112
+ canvas.drawPaint(mPaint);
113
+ } else {
114
+ canvas.drawPath(mPathForBorderRadius, mPaint);
115
+ }
116
+ }
117
+ }