Skip to content

Commit 59f963a

Browse files
authored
refactor(ios): use codegen enum types instead of NSInteger casts (#612)
* refactor(ios): use codegen enum types instead of NSInteger casts * docs: update changelog for #612
1 parent 82ee9f0 commit 59f963a

12 files changed

Lines changed: 54 additions & 47 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
### 💡 Others
2020

21+
- **iOS**: Use codegen enum types instead of `NSInteger` casts for better type safety. ([#612](https://github.com/lodev09/react-native-true-sheet/pull/612) by [@lodev09](https://github.com/lodev09))
2122
- Add docs versioning with automated release script. ([#586](https://github.com/lodev09/react-native-true-sheet/pull/586) by [@lodev09](https://github.com/lodev09))
2223

2324
### ⚠️ Breaking

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# React Native True Sheet
1+
# React Native TrueSheet
22

33
[![CI](https://github.com/lodev09/react-native-true-sheet/actions/workflows/checks.yml/badge.svg)](https://github.com/lodev09/react-native-true-sheet/actions/workflows/checks.yml)
44
[![NPM Downloads](https://img.shields.io/npm/d18m/%40lodev09%2Freact-native-true-sheet)](https://www.npmjs.com/package/@lodev09/react-native-true-sheet)

ios/TrueSheetContainerView.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010

1111
#import <React/RCTViewComponentView.h>
1212
#import <UIKit/UIKit.h>
13+
#import <react/renderer/components/TrueSheetSpec/Props.h>
1314

1415
NS_ASSUME_NONNULL_BEGIN
1516

1617
@interface ScrollableOptions : NSObject
1718

1819
@property (nonatomic, assign) CGFloat keyboardScrollOffset;
1920
@property (nonatomic, assign) BOOL scrollingExpandsSheet;
20-
@property (nonatomic, assign) NSInteger topScrollEdgeEffect;
21-
@property (nonatomic, assign) NSInteger bottomScrollEdgeEffect;
21+
@property (nonatomic, assign) facebook::react::TrueSheetViewTopScrollEdgeEffect topScrollEdgeEffect;
22+
@property (nonatomic, assign) facebook::react::TrueSheetViewBottomScrollEdgeEffect bottomScrollEdgeEffect;
2223

2324
@end
2425

@@ -48,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
4849
/**
4950
* Inset adjustment mode for scrollable content
5051
*/
51-
@property (nonatomic, assign) NSInteger insetAdjustment;
52+
@property (nonatomic, assign) facebook::react::TrueSheetViewInsetAdjustment insetAdjustment;
5253

5354
/**
5455
* Options for scrollable behavior

ios/TrueSheetContainerView.mm

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ - (instancetype)init {
3535
if (self = [super init]) {
3636
_keyboardScrollOffset = 0;
3737
_scrollingExpandsSheet = YES;
38-
_topScrollEdgeEffect = (NSInteger)TrueSheetViewTopScrollEdgeEffect::Hidden;
39-
_bottomScrollEdgeEffect = (NSInteger)TrueSheetViewBottomScrollEdgeEffect::Hidden;
38+
_topScrollEdgeEffect = TrueSheetViewTopScrollEdgeEffect::Hidden;
39+
_bottomScrollEdgeEffect = TrueSheetViewBottomScrollEdgeEffect::Hidden;
4040
}
4141
return self;
4242
}
@@ -113,7 +113,7 @@ - (void)setScrollableOptions:(ScrollableOptions *)scrollableOptions {
113113
- (void)setupScrollable {
114114
if (_scrollableSet && _contentView) {
115115
CGFloat bottomInset = 0;
116-
if (_insetAdjustment == (NSInteger)TrueSheetViewInsetAdjustment::Automatic) {
116+
if (_insetAdjustment == TrueSheetViewInsetAdjustment::Automatic) {
117117
bottomInset = [WindowUtil keyWindow].safeAreaInsets.bottom;
118118
}
119119
[_contentView setupScrollable:_scrollableEnabled bottomInset:bottomInset];
@@ -129,13 +129,13 @@ - (void)setupEdgeInteractions API_AVAILABLE(ios(26.0)) {
129129
return;
130130
}
131131

132-
NSInteger topEffect =
133-
_scrollableOptions ? _scrollableOptions.topScrollEdgeEffect : (NSInteger)TrueSheetViewTopScrollEdgeEffect::Hidden;
134-
NSInteger bottomEffect = _scrollableOptions ? _scrollableOptions.bottomScrollEdgeEffect
135-
: (NSInteger)TrueSheetViewBottomScrollEdgeEffect::Hidden;
132+
auto topEffect =
133+
_scrollableOptions ? _scrollableOptions.topScrollEdgeEffect : TrueSheetViewTopScrollEdgeEffect::Hidden;
134+
auto bottomEffect = _scrollableOptions ? _scrollableOptions.bottomScrollEdgeEffect
135+
: TrueSheetViewBottomScrollEdgeEffect::Hidden;
136136

137-
BOOL topHidden = topEffect == (NSInteger)TrueSheetViewTopScrollEdgeEffect::Hidden;
138-
BOOL bottomHidden = bottomEffect == (NSInteger)TrueSheetViewBottomScrollEdgeEffect::Hidden;
137+
BOOL topHidden = topEffect == TrueSheetViewTopScrollEdgeEffect::Hidden;
138+
BOOL bottomHidden = bottomEffect == TrueSheetViewBottomScrollEdgeEffect::Hidden;
139139

140140
RCTScrollViewComponentView *scrollViewComponent = [_contentView findScrollView];
141141
UIScrollView *scrollView = scrollViewComponent.scrollView;

ios/TrueSheetContentView.mm

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,32 +211,34 @@ - (void)applyScrollEdgeEffects:(nullable ScrollableOptions *)options {
211211

212212
if (@available(iOS 26.0, *)) {
213213
UIScrollView *scrollView = _pinnedScrollView.scrollView;
214-
NSInteger topEffect = options ? options.topScrollEdgeEffect : (NSInteger)TrueSheetViewTopScrollEdgeEffect::Hidden;
215-
NSInteger bottomEffect =
216-
options ? options.bottomScrollEdgeEffect : (NSInteger)TrueSheetViewBottomScrollEdgeEffect::Hidden;
214+
auto topEffect = options ? options.topScrollEdgeEffect : TrueSheetViewTopScrollEdgeEffect::Hidden;
215+
auto bottomEffect =
216+
options ? options.bottomScrollEdgeEffect : TrueSheetViewBottomScrollEdgeEffect::Hidden;
217217

218218
[self applyEdgeEffect:topEffect toEdge:scrollView.topEdgeEffect];
219-
[self applyEdgeEffect:bottomEffect toEdge:scrollView.bottomEdgeEffect];
219+
[self applyEdgeEffect:(TrueSheetViewTopScrollEdgeEffect)bottomEffect
220+
toEdge:scrollView.bottomEdgeEffect];
220221
}
221222
#endif
222223
}
223224

224225
#if RNTS_IPHONE_OS_VERSION_AVAILABLE(26_0)
225-
- (void)applyEdgeEffect:(NSInteger)effect toEdge:(UIScrollEdgeEffect *)edgeEffect API_AVAILABLE(ios(26.0)) {
226+
- (void)applyEdgeEffect:(TrueSheetViewTopScrollEdgeEffect)effect
227+
toEdge:(UIScrollEdgeEffect *)edgeEffect API_AVAILABLE(ios(26.0)) {
226228
switch (effect) {
227-
case (NSInteger)TrueSheetViewTopScrollEdgeEffect::Automatic:
229+
case TrueSheetViewTopScrollEdgeEffect::Automatic:
228230
edgeEffect.hidden = NO;
229231
edgeEffect.style = UIScrollEdgeEffectStyle.automaticStyle;
230232
break;
231-
case (NSInteger)TrueSheetViewTopScrollEdgeEffect::Hard:
233+
case TrueSheetViewTopScrollEdgeEffect::Hard:
232234
edgeEffect.hidden = NO;
233235
edgeEffect.style = UIScrollEdgeEffectStyle.hardStyle;
234236
break;
235-
case (NSInteger)TrueSheetViewTopScrollEdgeEffect::Soft:
237+
case TrueSheetViewTopScrollEdgeEffect::Soft:
236238
edgeEffect.hidden = NO;
237239
edgeEffect.style = UIScrollEdgeEffectStyle.softStyle;
238240
break;
239-
case (NSInteger)TrueSheetViewTopScrollEdgeEffect::Hidden:
241+
case TrueSheetViewTopScrollEdgeEffect::Hidden:
240242
edgeEffect.hidden = YES;
241243
break;
242244
}

ios/TrueSheetView.mm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ @implementation TrueSheetView {
5151
UIView *_snapshotView;
5252
CGSize _lastStateSize;
5353
NSInteger _initialDetentIndex;
54-
NSInteger _insetAdjustment;
54+
TrueSheetViewInsetAdjustment _insetAdjustment;
5555
BOOL _scrollable;
5656
ScrollableOptions *_scrollableOptions;
5757
BOOL _initialDetentAnimated;
@@ -185,7 +185,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
185185
_controller.backgroundColor = RCTUIColorFromSharedColor(newProps.backgroundColor);
186186

187187
// Blur tint
188-
_controller.backgroundBlur = (NSInteger)newProps.backgroundBlur;
188+
_controller.backgroundBlur = newProps.backgroundBlur;
189189

190190
// Blur options
191191
const auto &blurOpts = newProps.blurOptions;
@@ -202,7 +202,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
202202
_controller.maxContentWidth = newProps.maxContentWidth != 0.0 ? @(newProps.maxContentWidth) : nil;
203203

204204
// Anchor
205-
_controller.anchor = (NSInteger)newProps.anchor;
205+
_controller.anchor = newProps.anchor;
206206

207207
_controller.grabber = newProps.grabber;
208208

@@ -245,11 +245,11 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
245245

246246
const auto &scrollableOpts = newProps.scrollableOptions;
247247
BOOL scrollingExpandsSheet = scrollableOpts.scrollingExpandsSheet;
248-
NSInteger topEdgeEffect = (NSInteger)scrollableOpts.topScrollEdgeEffect;
249-
NSInteger bottomEdgeEffect = (NSInteger)scrollableOpts.bottomScrollEdgeEffect;
248+
auto topEdgeEffect = scrollableOpts.topScrollEdgeEffect;
249+
auto bottomEdgeEffect = scrollableOpts.bottomScrollEdgeEffect;
250250
BOOL hasScrollableOptions = scrollableOpts.keyboardScrollOffset > 0 || !scrollingExpandsSheet ||
251-
topEdgeEffect != (NSInteger)TrueSheetViewTopScrollEdgeEffect::Hidden ||
252-
bottomEdgeEffect != (NSInteger)TrueSheetViewBottomScrollEdgeEffect::Hidden;
251+
topEdgeEffect != TrueSheetViewTopScrollEdgeEffect::Hidden ||
252+
bottomEdgeEffect != TrueSheetViewBottomScrollEdgeEffect::Hidden;
253253

254254
if (hasScrollableOptions) {
255255
ScrollableOptions *options = [[ScrollableOptions alloc] init];
@@ -264,7 +264,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
264264

265265
_controller.scrollingExpandsSheet = scrollingExpandsSheet;
266266

267-
_insetAdjustment = (NSInteger)newProps.insetAdjustment;
267+
_insetAdjustment = newProps.insetAdjustment;
268268
_controller.insetAdjustment = _insetAdjustment;
269269

270270
[self setupScrollable];

ios/TrueSheetViewController.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import <UIKit/UIKit.h>
10+
#import <react/renderer/components/TrueSheetSpec/Props.h>
1011
#import "core/TrueSheetDetentCalculator.h"
1112
#import "core/TrueSheetGrabberView.h"
1213

@@ -63,12 +64,12 @@ NS_ASSUME_NONNULL_BEGIN
6364
@property (nonatomic, assign) BOOL draggable;
6465
@property (nonatomic, assign) BOOL dimmed;
6566
@property (nonatomic, strong, nullable) NSNumber *dimmedDetentIndex;
66-
@property (nonatomic, assign) NSInteger backgroundBlur;
67+
@property (nonatomic, assign) facebook::react::TrueSheetViewBackgroundBlur backgroundBlur;
6768
@property (nonatomic, strong, nullable) NSNumber *blurIntensity;
6869
@property (nonatomic, assign) BOOL blurInteraction;
6970
@property (nonatomic, assign) BOOL pageSizing;
70-
@property (nonatomic, assign) NSInteger anchor;
71-
@property (nonatomic, assign) NSInteger insetAdjustment;
71+
@property (nonatomic, assign) facebook::react::TrueSheetViewAnchor anchor;
72+
@property (nonatomic, assign) facebook::react::TrueSheetViewInsetAdjustment insetAdjustment;
7273
@property (nonatomic, assign) BOOL scrollingExpandsSheet;
7374
@property (nonatomic, assign) BOOL dismissible;
7475
@property (nonatomic, assign) BOOL isPresented;

ios/TrueSheetViewController.mm

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ - (instancetype)init {
8787
_isTrackingPositionFromLayout = NO;
8888

8989
_blurInteraction = YES;
90-
_insetAdjustment = (NSInteger)TrueSheetViewInsetAdjustment::Automatic;
90+
_insetAdjustment = TrueSheetViewInsetAdjustment::Automatic;
9191
_detentCalculator = [[TrueSheetDetentCalculator alloc] init];
9292
_detentCalculator.delegate = self;
9393
}
@@ -128,7 +128,7 @@ - (CGFloat)screenHeight {
128128
}
129129

130130
- (CGFloat)detentBottomAdjustmentForHeight:(CGFloat)height {
131-
if (_insetAdjustment == (NSInteger)TrueSheetViewInsetAdjustment::Automatic) {
131+
if (_insetAdjustment == TrueSheetViewInsetAdjustment::Automatic) {
132132
return 0;
133133
}
134134

@@ -717,16 +717,16 @@ - (void)resizeToDetentIndex:(NSInteger)index {
717717
}
718718

719719
- (void)setupBackground {
720-
NSInteger effectiveBackgroundBlur = self.backgroundBlur;
720+
auto effectiveBackgroundBlur = self.backgroundBlur;
721721
if (@available(iOS 26.0, *)) {
722722
// iOS 26+ has default liquid glass effect
723-
} else if (effectiveBackgroundBlur == (NSInteger)TrueSheetViewBackgroundBlur::None && !self.backgroundColor) {
724-
effectiveBackgroundBlur = (NSInteger)TrueSheetViewBackgroundBlur::SystemMaterial;
723+
} else if (effectiveBackgroundBlur == TrueSheetViewBackgroundBlur::None && !self.backgroundColor) {
724+
effectiveBackgroundBlur = TrueSheetViewBackgroundBlur::SystemMaterial;
725725
}
726726

727-
BOOL hasBlur = effectiveBackgroundBlur != (NSInteger)TrueSheetViewBackgroundBlur::None;
727+
BOOL hasBlur = effectiveBackgroundBlur != TrueSheetViewBackgroundBlur::None;
728728

729-
_blurView.backgroundBlur = hasBlur ? effectiveBackgroundBlur : (NSInteger)TrueSheetViewBackgroundBlur::None;
729+
_blurView.backgroundBlur = hasBlur ? effectiveBackgroundBlur : TrueSheetViewBackgroundBlur::None;
730730
_blurView.blurIntensity = self.blurIntensity;
731731
_blurView.blurInteraction = self.blurInteraction;
732732
[_blurView applyBlurEffect];
@@ -825,7 +825,7 @@ - (void)handleGrabberTap {
825825
}
826826

827827
- (BOOL)isAnchored {
828-
return self.anchor == (NSInteger)TrueSheetViewAnchor::Left || self.anchor == (NSInteger)TrueSheetViewAnchor::Right;
828+
return self.anchor == TrueSheetViewAnchor::Left || self.anchor == TrueSheetViewAnchor::Right;
829829
}
830830

831831
- (void)setupAnchorViewInView:(UIView *)parentView {
@@ -846,7 +846,7 @@ - (void)setupAnchorViewInView:(UIView *)parentView {
846846
[parentView addSubview:_anchorView];
847847

848848
NSLayoutAnchor *horizontalAnchor =
849-
self.anchor == (NSInteger)TrueSheetViewAnchor::Right ? parentView.trailingAnchor : parentView.leadingAnchor;
849+
self.anchor == TrueSheetViewAnchor::Right ? parentView.trailingAnchor : parentView.leadingAnchor;
850850

851851
[NSLayoutConstraint activateConstraints:@[
852852
[_anchorView.bottomAnchor constraintEqualToAnchor:parentView.bottomAnchor],

ios/core/TrueSheetBlurView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
//
88

99
#import <UIKit/UIKit.h>
10+
#import <react/renderer/components/TrueSheetSpec/Props.h>
1011

1112
NS_ASSUME_NONNULL_BEGIN
1213

1314
@interface TrueSheetBlurView : UIVisualEffectView
1415

15-
@property (nonatomic, assign) NSInteger backgroundBlur;
16+
@property (nonatomic, assign) facebook::react::TrueSheetViewBackgroundBlur backgroundBlur;
1617
@property (nonatomic, strong, nullable) NSNumber *blurIntensity;
1718
@property (nonatomic, assign) BOOL blurInteraction;
1819

ios/core/TrueSheetBlurView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ - (void)clearAnimator {
4848
- (void)applyBlurEffect {
4949
self.userInteractionEnabled = self.blurInteraction;
5050

51-
if (self.backgroundBlur == (NSInteger)TrueSheetViewBackgroundBlur::None) {
51+
if (self.backgroundBlur == TrueSheetViewBackgroundBlur::None) {
5252
[self clearAnimator];
5353
self.effect = nil;
5454
return;

0 commit comments

Comments
 (0)