我有一个垂直FlatList组件和两个按钮TouchableOpacity,如何使用FlatList按钮执行滚动,
即“将 FlatList 滚动到底部”和“将 FlatList 滚动到顶部”?
最小示例:
<View>
<FlatList/>
<TouchableOpacity>
<Text>Scroll towards Top</>Text
</TouchableOpacity>
<TouchableOpacity>
<Text>Scroll towards Bottom</>Text
</TouchableOpacity>
</View>
Run Code Online (Sandbox Code Playgroud) 我正在将 iOS 原生 SDK 集成到 React-Native 中。SDK.getCardData我想从 RN 中使用一个名为的函数。我的第一次尝试是在闭包内调用resolveand :reject
import Foundation
import SDK
@objc(SwiftComponentManager)
class SwiftComponentManager: NSObject {
@objc
func getCardData(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
let cardId: String = "test"
let secret: String = "test"
SDK.getCardData(cardId, secret: secret) { (cardData, error) in
if (error != nil) {
reject(String(format: "Card data request failed: %@", error!.localizedDescription))
} else {
let pan = cardData!.pan
let cvv = cardData!.cvv
resolve(String(format: "Card data fetched successfully, …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作搜索栏。我希望用户输入一些内容TextInput,当用户按“Enter”时我想调用我的函数。
<TextInput
//here when user press enter call function()
style={styles.searchStyle}
allowFontScaling={false}
placeholder="Search"
onChangeText={(val) => {setSearch(val)}}
/>
Run Code Online (Sandbox Code Playgroud)
我尝试过onSubmitEditing,但没有成功。
我正在开发的应用程序iOS 14.5之一更新后,Firebase 日志就停止工作。react-native
为了使其再次运行,我们需要做哪些必要的改变?
我会尝试:Source(React-Native事件中的两个函数)
onValueChange={(selected) => {
this.setState({selected});
this.state.eventOnChange();
}}
但这是行不通的
那执行第一个功能,但不执行第二个功能。
我想更新我的列表视图行,因为我正尝试对列表视图数据源进行切片,但其引发以下错误:
this.state.dataSource.slice不是函数。(在“ this.state.dataSource.slice()”中,“ this.state.dataSource.slice”未定义)
这是我的代码:
let newArray = this.state.dataSource.slice();
newArray[indexToUpdate] = {
//Here I am updating my values.
};
this.setState({
dataSource: this.state.dataSource.cloneWithRows(newArray),
});
Run Code Online (Sandbox Code Playgroud)
让我知道代码中是否有错误或做错了什么。
我想将异常消息转换为NSError对象,以便可以在try-catch块中使用它(我实际上是在React Native的本机iOS模块上工作)。
RCT_EXPORT_METHOD(myMethod:(NSDictionary *)dict
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@try {
// Do something which could throw something (NS Error or NS Exception)
resolve(nil);
} @catch (NSException *exception) {
// HERE I WANT TO TRANSFORM THE EXCEPTION exception INTO AN ERROR error
NSError error = ???
reject(@"my_error", @"Could not do something important", error);
}
}
Run Code Online (Sandbox Code Playgroud)
我想将异常转换为,NSError因为reject函数的第三个参数(拒绝JS端的Promise)期望输入的类型为NSError。我不确定我的解决方案(使用try-catch)在这种情况下是否是最好的方法。
您可以将异常转换为NSError对象,然后在警报面板中将错误对象中的信息呈现给用户。
但是,该指南并未显示该示例的代码示例,而仅显示了第二种方法的代码示例。您也可以在包含错误参数的方法中间接返回它们,这些错误参数对于我想要的而言似乎很复杂。
那么,如何将异常转换为NSError?NSError的API参考似乎不包含合适的功能。
我正在用React Native构建一个iOS应用程序.这样做,我安装了一个react-native模块并按照模块教程配置了我的iOS xcode项目(主要是cocoapods).现在,当我运行时react-native run-ios,我得到这个错误堆栈:
架构x86_64的未定义符号:
"_JSNoBytecodeFileFormatVersion",引自:
RCTJavaScriptLoader.o中的[RCTJavaScriptLoader loadBundleAtURL:onProgress:onComplete:]
+ [RCTJavaScriptLoader attemptSynchronousLoadOfBundleAtURL:runtimeBCVersion:sourceLength:error:]在RCTJavaScriptLoader.o"facebook :: react :: IRemoteConnection :: ~IRemoteConnection()"中,引自:
RCTInspector.o中的RemoteConnection :: ~RemoteConnection()"facebook :: react :: parseTypeFromHeader(facebook :: react :: BundleHeader const&)",引用自:
+ [RCTJavaScriptLoader attemptSynchronousLoadOfBundleAtURL:runtimeBCVersion:sourceLength:error:]在RCTJavaScriptLoader.o中
"facebook :: react :: customJSCWrapper()",引自:
- RCTDevSettings.o中的[RCTDevSettings isJSCSamplingProfilerAvailable]
- RCTInspector.o中的RCTDevSettings.o ____ZL11getInstancev_block_invoke中的[RCTDevSettings toggleJSCSamplingProfiler]
RCTJSCErrorHandling.o中的_RCTNSErrorFromJSErrorRef
- RCTSamplingProfilerPackagerMethod.o中的[RCTSamplingProfilerPackagerMethod handleRequest:withResponder:]
"facebook :: react :: systemJSCWrapper()",引自:
- RCTDevSettings.o中的[RCTDevSettings isJSCSamplingProfilerAvailable]
- RCTDevSettings.o中的[RCTDevSettings toggleJSCSamplingProfiler]
RCTJSCErrorHandling.o中的_RCTNSErrorFromJSErrorRef
- RCTSamplingProfilerPackagerMethod.o中的[RCTSamplingProfilerPackagerMethod handleRequest:withResponder:]
ld:找不到架构x86_64的符号
clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
**建筑失败**
以下构建命令失败:
Ld /Users/antoine/R/devlab/ReactNative/medway-twilio/MedwayTwilio/ios/build/Build/Products/Debug-iphonesimulator/React/React.framework/React normal x86_64(1 failure)
我怀疑这与使用xcode将项目库和框架包含在项目中有关,但我不确定.
这是我的项目目标/构建阶段/链接二进制文件的截图,其中包含xcode中的库面板:
"MedwayTwilio"是我的项目名称
我有一个数组:
const routes = [
{ id: 1, title: 'Home', image: 'home', cstyle: 'styles.ItemsDrawer' },
{ id: 2, title: 'Chat', image: 'flask', cstyle: 'styles.ItemsDrawer' },
{ id: 3, title: 'Profile', image: 'briefcase', cstyle: 'styles.ItemsDrawer' },
{ id: 5, title: 'Logout', image: 'log-out', cstyle: 'styles.logout' }
];
Run Code Online (Sandbox Code Playgroud)
并希望应用于某些款式不同的款式,
<List dataArray={routes}
renderRow={(data) =>
<ListItem style={data.cstyle}
button onPress={() => ctx.navigate(data.title)} icon>
</ListItem>}>
</List>
Run Code Online (Sandbox Code Playgroud)
但我认为传递"data.cstyle"它会采取一个名称,并尝试在节样式表中找到它的样式,但这不能识别并保留没有样式到列表动态的每个项目
或者如何将不同的样式应用于列表中的某些项目
随装 yarn install react-native-unimodules
说明中的下一步要求我编辑项目Podfile。此处显示了必要的添加。
这是我生成的Podfile
platform :ios, '10.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-unimodules/cocoapods.rb'
target 'MyProjectName' do
# Pods for MyProjectName
pod 'React', :path => '../node_modules/react-native/', :subspecs => [
'Core',
'CxxBridge',
'DevSupport',
'RCTText',
'RCTNetwork',
'RCTWebSocket',
'RCTAnimation',
'RCTImage',
]
pod 'React-Core', :path => '../node_modules/react-native/React'
pod 'React-DevSupport', :path => '../node_modules/react-native/React'
pod 'React-fishhook', :path => '../node_modules/react-native/Libraries/fishhook'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod …Run Code Online (Sandbox Code Playgroud) react-native-ios ×10
react-native ×8
cocoapods ×2
bridge ×1
firebase ×1
ios ×1
ios14 ×1
javascript ×1
native-base ×1
node.js ×1
objective-c ×1
podfile ×1
podspec ×1
promise ×1
swift ×1
xcode ×1