Skip to content

Commit 3032a90

Browse files
committed
chore: better scripts and dev dependencies also activeTextStyle prop is back
1 parent 03ba26f commit 3032a90

File tree

11 files changed

+8042
-24191
lines changed

11 files changed

+8042
-24191
lines changed

.eslintrc.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports = {
44
"eslint:recommended",
55
"plugin:react/recommended",
66
"plugin:@typescript-eslint/recommended",
7-
"@react-native-community",
87
"prettier",
98
],
109
ignorePatterns: [
@@ -25,16 +24,17 @@ module.exports = {
2524
"react-hooks",
2625
"@typescript-eslint",
2726
"promise",
28-
"jest",
2927
"unused-imports",
3028
],
3129
env: {
3230
browser: true,
3331
es2021: true,
34-
"jest/globals": true,
3532
"react-native/react-native": true,
3633
},
3734
settings: {
35+
react: {
36+
version: "detect",
37+
},
3838
"import/resolver": {
3939
node: {
4040
extensions: [
@@ -58,6 +58,14 @@ module.exports = {
5858
],
5959
},
6060
},
61+
// Ensure the import plugin does not try to parse node_modules with the TS parser
62+
"import/parsers": {
63+
"@typescript-eslint/parser": [".ts", ".tsx"],
64+
},
65+
// Treat react-native as a core module and skip deep parsing
66+
"import/core-modules": ["react-native"],
67+
// And in general, do not attempt to parse files in node_modules
68+
"import/ignore": ["node_modules/"],
6169
},
6270
rules: {
6371
quotes: [
@@ -80,10 +88,12 @@ module.exports = {
8088
constant: "always",
8189
},
8290
],
83-
"no-useless-catch": 0,
84-
"react-hooks/exhaustive-deps": 0,
91+
"react-hooks/exhaustive-deps": [
92+
"error",
93+
{ additionalHooks: "(useMemoOne)" },
94+
],
8595
"max-len": ["error", 120],
86-
"@typescript-eslint/ban-ts-comment": 1,
96+
"@typescript-eslint/ban-ts-comment": 2,
8797
"@typescript-eslint/no-empty-function": 0,
8898
"@typescript-eslint/no-explicit-any": 1,
8999
"@typescript-eslint/explicit-module-boundary-types": 0,
@@ -110,6 +120,8 @@ module.exports = {
110120
"import/no-deprecated": 0,
111121
"@typescript-eslint/indent": 0,
112122
"react-hooks/rules-of-hooks": 2,
123+
"unused-imports/no-unused-imports": 2,
124+
"unused-imports/no-unused-vars": 2,
113125
camelcase: 2,
114126
"prefer-destructuring": 2,
115127
"no-nested-ternary": 2,

lib/SegmentedControl.style.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Animated, StyleSheet } from "react-native";
22

3-
export default StyleSheet.create<any>({
3+
const baseStyles = StyleSheet.create({
44
container: {
55
display: "flex",
66
width: "90%",
@@ -19,6 +19,15 @@ export default StyleSheet.create<any>({
1919
alignItems: "center",
2020
justifyContent: "center",
2121
},
22+
textStyle: {
23+
fontSize: 14, // iOS Default
24+
textAlign: "center",
25+
fontWeight: "500",
26+
},
27+
});
28+
29+
const styles = {
30+
...baseStyles,
2231
activeTab: (
2332
tabWidth: number,
2433
gap: number,
@@ -40,9 +49,6 @@ export default StyleSheet.create<any>({
4049
},
4150
elevation: 4,
4251
}),
43-
textStyle: {
44-
fontSize: 14, // iOS Default
45-
textAlign: "center",
46-
fontWeight: "500",
47-
},
48-
});
52+
} as const;
53+
54+
export default styles;

lib/SegmentedControl.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import {
1313
} from "react-native";
1414
import styles from "./SegmentedControl.style";
1515

16+
type TabItem = string | React.ReactElement;
17+
1618
interface SegmentedControlProps {
17-
tabs: any[];
19+
tabs: TabItem[];
1820
initialIndex?: number;
1921
activeTextColor?: string;
2022
activeTabColor?: string;
@@ -42,7 +44,7 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
4244
activeTextColor = "#000",
4345
activeTabColor = "#fff",
4446
}) => {
45-
const [slideAnimation, _] = useState(new Animated.Value(0));
47+
const [slideAnimation] = useState(new Animated.Value(0));
4648
const [localCurrentIndex, setCurrentIndex] = useState<number>(initialIndex);
4749
const [tabLayouts, setTabLayouts] = useState<{
4850
[tabIndex: number]: LayoutRectangle;
@@ -101,10 +103,17 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
101103
]}
102104
/>
103105
),
104-
[activeTabColor, gap, selectedTabStyle, slideAnimation, tabLayouts],
106+
[
107+
activeTabColor,
108+
gap,
109+
selectedTabStyle,
110+
slideAnimation,
111+
tabLayouts,
112+
currentIndex,
113+
],
105114
);
106115

107-
const renderTab = (tab: any, index: number) => {
116+
const renderTab = (tab: TabItem, index: number) => {
108117
const isActiveTab = currentIndex === index;
109118
const isTabText = typeof tab === "string";
110119
return (

0 commit comments

Comments
 (0)