Skip to content

Commit 6d37399

Browse files
chore: add linting, formatting, and CI tooling
Add lefthook pre-commit hooks (eslint + tsc) and commit-msg (commitlint). Add clang-format for iOS/Android native code formatting. Add release-it with conventional changelog for releases. Add format:check/write scripts for prettier and clang-format. Split lint into lint:eslint and lint:ts. Add format:check to CI. Add react-native.config.js for Android componentDescriptors.
1 parent 0257732 commit 6d37399

10 files changed

Lines changed: 4009 additions & 228 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ jobs:
2525
- name: Setup
2626
uses: ./.github/actions/setup
2727

28-
- name: Lint files
29-
run: yarn lint
30-
31-
- name: Typecheck files
32-
run: yarn typecheck
28+
- name: Check format
29+
run: yarn format:check
3330

31+
- name: Check lint
32+
run: yarn lint
3433

3534
build-library:
3635
runs-on: ubuntu-latest

example/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ module.exports = getConfig(
88
{
99
presets: ['module:@react-native/babel-preset'],
1010
},
11-
{ root, pkg }
11+
{ root, pkg },
1212
);

example/src/App.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import {
99
} from 'react-native';
1010
import { EaseView } from 'react-native-ease';
1111

12-
function Section({ title, children }: { title: string; children: React.ReactNode }) {
12+
function Section({
13+
title,
14+
children,
15+
}: {
16+
title: string;
17+
children: React.ReactNode;
18+
}) {
1319
return (
1420
<View style={styles.section}>
1521
<Text style={styles.sectionTitle}>{title}</Text>

ios/EaseView.mm

Lines changed: 81 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,30 @@ static inline CGFloat degreesToRadians(CGFloat degrees) {
2222
return degrees * M_PI / 180.0;
2323
}
2424

25-
static CAMediaTimingFunction *timingFunctionForEasing(EaseViewTransitionEasing easing) {
25+
static CAMediaTimingFunction *
26+
timingFunctionForEasing(EaseViewTransitionEasing easing) {
2627
switch (easing) {
27-
case EaseViewTransitionEasing::Linear:
28-
return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
29-
case EaseViewTransitionEasing::EaseIn:
30-
return [CAMediaTimingFunction functionWithControlPoints:0.42 :0.0 :1.0 :1.0];
31-
case EaseViewTransitionEasing::EaseOut:
32-
return [CAMediaTimingFunction functionWithControlPoints:0.0 :0.0 :0.58 :1.0];
33-
case EaseViewTransitionEasing::EaseInOut:
34-
return [CAMediaTimingFunction functionWithControlPoints:0.42 :0.0 :0.58 :1.0];
28+
case EaseViewTransitionEasing::Linear:
29+
return
30+
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
31+
case EaseViewTransitionEasing::EaseIn:
32+
return [CAMediaTimingFunction functionWithControlPoints:0.42:0.0:1.0:1.0];
33+
case EaseViewTransitionEasing::EaseOut:
34+
return [CAMediaTimingFunction functionWithControlPoints:0.0:0.0:0.58:1.0];
35+
case EaseViewTransitionEasing::EaseInOut:
36+
return [CAMediaTimingFunction functionWithControlPoints:0.42:0.0:0.58:1.0];
3537
}
3638
}
3739

3840
@implementation EaseView {
3941
BOOL _isFirstMount;
4042
}
4143

42-
+ (ComponentDescriptorProvider)componentDescriptorProvider
43-
{
44+
+ (ComponentDescriptorProvider)componentDescriptorProvider {
4445
return concreteComponentDescriptorProvider<EaseViewComponentDescriptor>();
4546
}
4647

47-
- (instancetype)initWithFrame:(CGRect)frame
48-
{
48+
- (instancetype)initWithFrame:(CGRect)frame {
4949
if (self = [super initWithFrame:frame]) {
5050
static const auto defaultProps = std::make_shared<const EaseViewProps>();
5151
_props = defaultProps;
@@ -56,8 +56,7 @@ - (instancetype)initWithFrame:(CGRect)frame
5656

5757
#pragma mark - Animation helpers
5858

59-
- (NSValue *)presentationValueForKeyPath:(NSString *)keyPath
60-
{
59+
- (NSValue *)presentationValueForKeyPath:(NSString *)keyPath {
6160
CALayer *presentationLayer = self.layer.presentationLayer;
6261
if (presentationLayer) {
6362
return [presentationLayer valueForKeyPath:keyPath];
@@ -68,10 +67,10 @@ - (NSValue *)presentationValueForKeyPath:(NSString *)keyPath
6867
- (CAAnimation *)createAnimationForKeyPath:(NSString *)keyPath
6968
fromValue:(NSValue *)fromValue
7069
toValue:(NSValue *)toValue
71-
props:(const EaseViewProps &)props
72-
{
70+
props:(const EaseViewProps &)props {
7371
if (props.transitionType == EaseViewTransitionType::Spring) {
74-
CASpringAnimation *spring = [CASpringAnimation animationWithKeyPath:keyPath];
72+
CASpringAnimation *spring =
73+
[CASpringAnimation animationWithKeyPath:keyPath];
7574
spring.fromValue = fromValue;
7675
spring.toValue = toValue;
7776
spring.damping = props.transitionDamping;
@@ -98,8 +97,7 @@ - (void)applyAnimationForKeyPath:(NSString *)keyPath
9897
animationKey:(NSString *)animationKey
9998
fromValue:(NSValue *)fromValue
10099
toValue:(NSValue *)toValue
101-
props:(const EaseViewProps &)props
102-
{
100+
props:(const EaseViewProps &)props {
103101
[CATransaction begin];
104102
[CATransaction setDisableActions:YES];
105103
[self.layer setValue:toValue forKeyPath:keyPath];
@@ -112,8 +110,7 @@ - (void)applyAnimationForKeyPath:(NSString *)keyPath
112110
[self.layer addAnimation:animation forKey:animationKey];
113111
}
114112

115-
- (void)setModelValue:(NSValue *)value forKeyPath:(NSString *)keyPath
116-
{
113+
- (void)setModelValue:(NSValue *)value forKeyPath:(NSString *)keyPath {
117114
[CATransaction begin];
118115
[CATransaction setDisableActions:YES];
119116
[self.layer setValue:value forKeyPath:keyPath];
@@ -122,28 +119,37 @@ - (void)setModelValue:(NSValue *)value forKeyPath:(NSString *)keyPath
122119

123120
#pragma mark - Props update
124121

125-
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
126-
{
127-
const auto &newViewProps = *std::static_pointer_cast<const EaseViewProps>(props);
122+
- (void)updateProps:(const Props::Shared &)props
123+
oldProps:(const Props::Shared &)oldProps {
124+
const auto &newViewProps =
125+
*std::static_pointer_cast<const EaseViewProps>(props);
128126

129127
if (_isFirstMount) {
130128
_isFirstMount = NO;
131129

132130
BOOL hasInitialAnimation =
133-
newViewProps.initialAnimateOpacity != newViewProps.animateOpacity ||
134-
newViewProps.initialAnimateTranslateX != newViewProps.animateTranslateX ||
135-
newViewProps.initialAnimateTranslateY != newViewProps.animateTranslateY ||
136-
newViewProps.initialAnimateScale != newViewProps.animateScale ||
137-
newViewProps.initialAnimateRotate != newViewProps.animateRotate;
131+
newViewProps.initialAnimateOpacity != newViewProps.animateOpacity ||
132+
newViewProps.initialAnimateTranslateX !=
133+
newViewProps.animateTranslateX ||
134+
newViewProps.initialAnimateTranslateY !=
135+
newViewProps.animateTranslateY ||
136+
newViewProps.initialAnimateScale != newViewProps.animateScale ||
137+
newViewProps.initialAnimateRotate != newViewProps.animateRotate;
138138

139139
if (hasInitialAnimation) {
140140
// Set initial values immediately
141-
[self setModelValue:@(newViewProps.initialAnimateOpacity) forKeyPath:@"opacity"];
142-
[self setModelValue:@(newViewProps.initialAnimateTranslateX) forKeyPath:@"transform.translation.x"];
143-
[self setModelValue:@(newViewProps.initialAnimateTranslateY) forKeyPath:@"transform.translation.y"];
144-
[self setModelValue:@(newViewProps.initialAnimateScale) forKeyPath:@"transform.scale.x"];
145-
[self setModelValue:@(newViewProps.initialAnimateScale) forKeyPath:@"transform.scale.y"];
146-
[self setModelValue:@(degreesToRadians(newViewProps.initialAnimateRotate)) forKeyPath:@"transform.rotation.z"];
141+
[self setModelValue:@(newViewProps.initialAnimateOpacity)
142+
forKeyPath:@"opacity"];
143+
[self setModelValue:@(newViewProps.initialAnimateTranslateX)
144+
forKeyPath:@"transform.translation.x"];
145+
[self setModelValue:@(newViewProps.initialAnimateTranslateY)
146+
forKeyPath:@"transform.translation.y"];
147+
[self setModelValue:@(newViewProps.initialAnimateScale)
148+
forKeyPath:@"transform.scale.x"];
149+
[self setModelValue:@(newViewProps.initialAnimateScale)
150+
forKeyPath:@"transform.scale.y"];
151+
[self setModelValue:@(degreesToRadians(newViewProps.initialAnimateRotate))
152+
forKeyPath:@"transform.rotation.z"];
147153

148154
// Animate from initial to target for properties that differ
149155
if (newViewProps.initialAnimateOpacity != newViewProps.animateOpacity) {
@@ -153,14 +159,16 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
153159
toValue:@(newViewProps.animateOpacity)
154160
props:newViewProps];
155161
}
156-
if (newViewProps.initialAnimateTranslateX != newViewProps.animateTranslateX) {
162+
if (newViewProps.initialAnimateTranslateX !=
163+
newViewProps.animateTranslateX) {
157164
[self applyAnimationForKeyPath:@"transform.translation.x"
158165
animationKey:kAnimKeyTranslateX
159166
fromValue:@(newViewProps.initialAnimateTranslateX)
160167
toValue:@(newViewProps.animateTranslateX)
161168
props:newViewProps];
162169
}
163-
if (newViewProps.initialAnimateTranslateY != newViewProps.animateTranslateY) {
170+
if (newViewProps.initialAnimateTranslateY !=
171+
newViewProps.animateTranslateY) {
164172
[self applyAnimationForKeyPath:@"transform.translation.y"
165173
animationKey:kAnimKeyTranslateY
166174
fromValue:@(newViewProps.initialAnimateTranslateY)
@@ -182,70 +190,84 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
182190
if (newViewProps.initialAnimateRotate != newViewProps.animateRotate) {
183191
[self applyAnimationForKeyPath:@"transform.rotation.z"
184192
animationKey:kAnimKeyRotate
185-
fromValue:@(degreesToRadians(newViewProps.initialAnimateRotate))
186-
toValue:@(degreesToRadians(newViewProps.animateRotate))
193+
fromValue:@(degreesToRadians(
194+
newViewProps.initialAnimateRotate))
195+
toValue:@(degreesToRadians(
196+
newViewProps.animateRotate))
187197
props:newViewProps];
188198
}
189199
} else {
190200
// No initial animation, set target values directly
191201
[self setModelValue:@(newViewProps.animateOpacity) forKeyPath:@"opacity"];
192-
[self setModelValue:@(newViewProps.animateTranslateX) forKeyPath:@"transform.translation.x"];
193-
[self setModelValue:@(newViewProps.animateTranslateY) forKeyPath:@"transform.translation.y"];
194-
[self setModelValue:@(newViewProps.animateScale) forKeyPath:@"transform.scale.x"];
195-
[self setModelValue:@(newViewProps.animateScale) forKeyPath:@"transform.scale.y"];
196-
[self setModelValue:@(degreesToRadians(newViewProps.animateRotate)) forKeyPath:@"transform.rotation.z"];
202+
[self setModelValue:@(newViewProps.animateTranslateX)
203+
forKeyPath:@"transform.translation.x"];
204+
[self setModelValue:@(newViewProps.animateTranslateY)
205+
forKeyPath:@"transform.translation.y"];
206+
[self setModelValue:@(newViewProps.animateScale)
207+
forKeyPath:@"transform.scale.x"];
208+
[self setModelValue:@(newViewProps.animateScale)
209+
forKeyPath:@"transform.scale.y"];
210+
[self setModelValue:@(degreesToRadians(newViewProps.animateRotate))
211+
forKeyPath:@"transform.rotation.z"];
197212
}
198213
} else {
199214
// Subsequent updates: animate changed properties
200-
const auto &oldViewProps = *std::static_pointer_cast<const EaseViewProps>(oldProps);
215+
const auto &oldViewProps =
216+
*std::static_pointer_cast<const EaseViewProps>(oldProps);
201217

202218
if (oldViewProps.animateOpacity != newViewProps.animateOpacity) {
203-
[self applyAnimationForKeyPath:@"opacity"
204-
animationKey:kAnimKeyOpacity
205-
fromValue:[self presentationValueForKeyPath:@"opacity"]
206-
toValue:@(newViewProps.animateOpacity)
207-
props:newViewProps];
219+
[self
220+
applyAnimationForKeyPath:@"opacity"
221+
animationKey:kAnimKeyOpacity
222+
fromValue:[self presentationValueForKeyPath:@"opacity"]
223+
toValue:@(newViewProps.animateOpacity)
224+
props:newViewProps];
208225
}
209226
if (oldViewProps.animateTranslateX != newViewProps.animateTranslateX) {
210227
[self applyAnimationForKeyPath:@"transform.translation.x"
211228
animationKey:kAnimKeyTranslateX
212-
fromValue:[self presentationValueForKeyPath:@"transform.translation.x"]
229+
fromValue:[self presentationValueForKeyPath:
230+
@"transform.translation.x"]
213231
toValue:@(newViewProps.animateTranslateX)
214232
props:newViewProps];
215233
}
216234
if (oldViewProps.animateTranslateY != newViewProps.animateTranslateY) {
217235
[self applyAnimationForKeyPath:@"transform.translation.y"
218236
animationKey:kAnimKeyTranslateY
219-
fromValue:[self presentationValueForKeyPath:@"transform.translation.y"]
237+
fromValue:[self presentationValueForKeyPath:
238+
@"transform.translation.y"]
220239
toValue:@(newViewProps.animateTranslateY)
221240
props:newViewProps];
222241
}
223242
if (oldViewProps.animateScale != newViewProps.animateScale) {
224243
[self applyAnimationForKeyPath:@"transform.scale.x"
225244
animationKey:kAnimKeyScaleX
226-
fromValue:[self presentationValueForKeyPath:@"transform.scale.x"]
245+
fromValue:[self presentationValueForKeyPath:
246+
@"transform.scale.x"]
227247
toValue:@(newViewProps.animateScale)
228248
props:newViewProps];
229249
[self applyAnimationForKeyPath:@"transform.scale.y"
230250
animationKey:kAnimKeyScaleY
231-
fromValue:[self presentationValueForKeyPath:@"transform.scale.y"]
251+
fromValue:[self presentationValueForKeyPath:
252+
@"transform.scale.y"]
232253
toValue:@(newViewProps.animateScale)
233254
props:newViewProps];
234255
}
235256
if (oldViewProps.animateRotate != newViewProps.animateRotate) {
236257
[self applyAnimationForKeyPath:@"transform.rotation.z"
237258
animationKey:kAnimKeyRotate
238-
fromValue:[self presentationValueForKeyPath:@"transform.rotation.z"]
239-
toValue:@(degreesToRadians(newViewProps.animateRotate))
259+
fromValue:[self presentationValueForKeyPath:
260+
@"transform.rotation.z"]
261+
toValue:@(degreesToRadians(
262+
newViewProps.animateRotate))
240263
props:newViewProps];
241264
}
242265
}
243266

244267
[super updateProps:props oldProps:oldProps];
245268
}
246269

247-
- (void)prepareForRecycle
248-
{
270+
- (void)prepareForRecycle {
249271
[super prepareForRecycle];
250272
[self.layer removeAllAnimations];
251273
_isFirstMount = YES;

lefthook.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pre-commit:
2+
parallel: true
3+
commands:
4+
5+
lint:
6+
glob: "*.{js,ts,jsx,tsx}"
7+
run: npx eslint {staged_files}
8+
9+
types:
10+
glob: "*.{js,ts, jsx, tsx}"
11+
run: npx tsc
12+
commit-msg:
13+
parallel: true
14+
commands:
15+
commitlint:
16+
run: npx commitlint --edit

0 commit comments

Comments
 (0)