MCPcopy
hub / github.com/ptomasroos/react-native-scrollable-tab-view / getInitialState

Function getInitialState

index.js:69–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67 },
68
69 getInitialState() {
70 const containerWidth = Dimensions.get('window').width;
71 let scrollValue;
72 let scrollXIOS;
73 let positionAndroid;
74 let offsetAndroid;
75
76 if (Platform.OS === 'ios') {
77 scrollXIOS = new Animated.Value(this.props.initialPage * containerWidth);
78 const containerWidthAnimatedValue = new Animated.Value(containerWidth);
79 // Need to call __makeNative manually to avoid a native animated bug. See
80 // https://github.com/facebook/react-native/pull/14435
81 containerWidthAnimatedValue.__makeNative();
82 scrollValue = Animated.divide(scrollXIOS, containerWidthAnimatedValue);
83
84 const callListeners = this._polyfillAnimatedValue(scrollValue);
85 scrollXIOS.addListener(
86 ({ value, }) => callListeners(value / this.state.containerWidth)
87 );
88 } else {
89 positionAndroid = new Animated.Value(this.props.initialPage);
90 offsetAndroid = new Animated.Value(0);
91 scrollValue = Animated.add(positionAndroid, offsetAndroid);
92
93 const callListeners = this._polyfillAnimatedValue(scrollValue);
94 let positionAndroidValue = this.props.initialPage;
95 let offsetAndroidValue = 0;
96 positionAndroid.addListener(({ value, }) => {
97 positionAndroidValue = value;
98 callListeners(positionAndroidValue + offsetAndroidValue);
99 });
100 offsetAndroid.addListener(({ value, }) => {
101 offsetAndroidValue = value;
102 callListeners(positionAndroidValue + offsetAndroidValue);
103 });
104 }
105
106 return {
107 currentPage: this.props.initialPage,
108 scrollValue,
109 scrollXIOS,
110 positionAndroid,
111 offsetAndroid,
112 containerWidth,
113 sceneKeys: this.newSceneKeys({ currentPage: this.props.initialPage, }),
114 };
115 },
116
117 componentDidUpdate(prevProps) {
118 if (this.props.children !== prevProps.children) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…