I created a native module using Swift called CounterView, and when I use it as such:
<CounterView style={{flex: 1}} />
I get this nasty warning! But the thing is, everything works. The error goes away if I remove the style prop, but nothing would render without the {flex: 1}. So I tried to wrap this inside a View, but then it renders relative to the entire screen rather than the wrapper. How can I get rid of this error? Am I doing something wrong to make my component "read-only"?
Type '{ style: { flex: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<unknown, {}, any> & Readonly<NativeMethods>> & Readonly<...> & Readonly<...>'.
Property 'style' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<unknown, {}, any> & Readonly<NativeMethods>> & Readonly<...> & Readonly<...>'.
I can circumvent the issue if I do this:
<View style={{flex: 1}}>
<View style={{flex: 1}} />
<View style={{flex: 1}}>
<CounterView />
</View>
</View>
This takes care of the other half of the screen that will be occupied by another flex:1 container, but this looks pretty silly.
Related
How do I know what native props are available for a component to use setNativeProps. In this example, the <TextInput> component doesn't have text as a prop but apparently setNativeProps use text instead of value as a prop. Thank you!
clearText = () => {
this._textInput.setNativeProps({text: ''});
}
render() {
return (
<View style={{flex: 1}}>
<TextInput
ref={component => this._textInput = component}
/>
<TouchableOpacity onPress={this.clearText}>
<Text>Clear text</Text>
</TouchableOpacity>
</View>
);
}
}
This is pretty common in react-native, due to limited documentation. Whenever looking for any information regarding react-native components, it is a good idea to simply look at the .js file you are using. In this case, TextInput, can be found...
Project/node_modules/react-native/Libraries/Components/TextInput/TextInput.js
Hope you can find what you're looking for - with a bit of digging. If you want to look further, looking into the RCT files is a good idea also.
Project/node_modules/react-native/Libraries/Text/RCTTextField.h
Project/node_modules/react-native/Libraries/Text/RCTTextView.h
I am a newbie developer. I'm currently developing apps using React-Native on two platforms, Android and iOS.
I have several constraints when designing this app on the two platforms I use. This app is similar to chat. For the wrapping compiler I use Listview. But there are constraints when running on the iOS platform.
My code is as follows:
<View style={Styles.container}>
<View style={Styles.conversation}>
{this.messages.length > 0
? <ListView
enableEmptySections
style={Styles.messageList}
ref={ref => (this.listView = ref)}
onContentSizeChange={(contentWidth, contentHeight) => {
this.listView.scrollTo({
y: contentHeight,
});
}
}}
dataSource={ds.cloneWithRows(this.messages)}
renderRow={item => <Message data={item} key={item.key} />}
/>
: <Text style={Styles.welcome_message}>Welcome to Kelle</Text>}
</View>
The code above on Android goes well. But when it runs on iOS, the chat text position in the Listview becomes random. Like the picture below:
Has anyone ever experienced anything like this? How should I solve this problem?
In react-native-ios, I am using react-native-datepicker for selecting date from calender.
For this, I am using following link:
Date Picker in react-native-ios
I am adding following code in my render method:
<View style={styles.buttonContainer}>
<TouchableOpacity
style={[styles.bubble, styles.button]}
onPress={() => this.openCalender()}>
<DatePicker
style={{width: 150}}
date={this.state.date}
mode="date"
placeholder="Date"
format="YYYY-MM-DD"
minDate="2015-01-01"
maxDate="2025-12-01"
confirmBtnText="Confirm"
cancelBtnText="Cancel"
iconSource={require('./assets/cal.png')}
onDateChange={(date) => {this.setState({date: date});}}
/>
</TouchableOpacity>
</View>
but I want to add this date picker in dialog. What will be the way for implementing that in react-native-ios.
I want to put Date picker on NavBar Right button click.
I am using this library : https://github.com/xgfe/react-native-datepicker
It works great and cross-platform too.
I am still not sure what you are trying to achieve, but your code above will not work unless you move the <DatePicker/> outside the <TouchableOpacity/>. Once you move that out it should open up the picker as expected by the package.
I'm learning React-Native .
I can find NavigatorIOS's demo (code) ,
I copy this code and write to webStorm , but webStorm throw Error .
This code :
_renderRow = (title: string, onPress: Function) => { // Error :'Types are not supported by current Javascript version !
return (
<View>
<TouchableHighlight onPress={onPress}>
<View style={styles.row}>
<Text style={styles.rowText}>
{title}
</Text>
</View>
</TouchableHighlight>
<View style={styles.separator} />
</View>
);
};
Error code :_renderRow = (title: string, onPress: Function) =>{...}
Error description:
string :'Types are not supported by current Javascript version !
Function :'Types are not supported by current Javascript version !
My WebStorm's Javascript language version is React JSX
Question:
1、Why the WebStorm cannot support string type and Function type ? this code is react-native example with Facebook !
2、I don't understand why this code is not ES6 code , I'm a iOS programmer , please help me , thanks .
Javascript don't support typed function parameters, which is why you have errors there.
I believe the reason you see that in the example is because they are using Flow
I have a simple ListView which seems to take a long time to load its items. I've tested in Release mode, and its taking about 3 seconds to load the whole page. If I set initialListSize={1} I can see it building the list item by item.
The ListView JSX code:
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow}
renderSeparator={(sectionID, rowID) => <View key={`${sectionID}-${rowID}`} style={styles.separator} />}
style={styles.listView}
initialListSize={1}
/>
And the renderRow method:
renderRow(row) {
// console.log ('rendering scale row: ' + row.numerator + ':' + row.denominator );
return (
<TouchableHighlight onPress={() => this.pressRow(row)} underlayColor="grey">
<View style={styles.rowContainer}>
<Text style={styles.rowText}>{row.hasOwnProperty('label') ? row.label : row.numerator + ':' + row.denominator}</Text>
<Text style={styles.rowText}>{row.hasOwnProperty('label') ? row.numerator + ':' + row.denominator : ''}</Text>
</View>
</TouchableHighlight>
);
}
I'm not doing anything very complicated in renderRow... and the data had already been fetched in a previous view and passed in via props.
Is there something I don't know about that could be affecting load/render time?
This is iOS only and on an iPhone 4S. Only 12-21 rows in my tests.
I should also add that the core of the app is using the JUCE C++ framework and running some audio processing in one of the views. I have an audio processing thread that is only run when that view is visible - all other views (including the one with this ListView) will stop the audio processing thread. I've tried also stopping the audio thread in a similar manner but it did not make any difference.
Not sure if this is going to help you, but I can think of three things you can try...
cmd+T will toggle "slow animations" on/off. This is a long shot
If you are writing to the console.log, comment out those lines. They can surprisingly bog things down considerably sometimes.
Turn off dev mode. You shouldn't need to, but worth a shot
Better start using FlatList or SectionList since ListView is now Deprecated.
https://facebook.github.io/react-native/docs/listview.html
There are few Caveats like you must use a FLUX/ REDUX or RELAY. Please Checkout the details here (Features/Caveats)
https://facebook.github.io/react-native/blog/2017/03/13/better-list-views.html