我正在做一个本机反应项目,用户可以使用Flickr API搜索图像,其他所有工作都很好,但是实现分页时遇到了问题。我已经使用FlatList onEndReached来检测用户何时滚动到列表的末尾,但是问题onEndReached却被调用了多次(包括第一次渲染期间)。我什至已禁用弹跳,如此处所说,但仍被多次调用
export default class BrowserHome extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: false,
tagParam: "cat",
pageNum: -1,
data: [],
photosObj: ""
};
}
componentDidMount() {
this.setState({
isLoading: true
});
try {
this.makeRequest();
} catch {
console.log("error has occurred");
}
}
makeRequest = () => {
const { tagParam, pageNum } = this.state;
let url = `https://api.flickr.com/services/rest/?
method=flickr.photos.search
&api_key=${apiKey}&format=json&tags=${tagParam}
&per_page=30&page=${pageNum + 1}&nojsoncallback=1`;
fetch(url, {
method: "GET"
})
.then(response => response.json())
.then(responseJSON …Run Code Online (Sandbox Code Playgroud) 我想要一个类似的功能,就像react 可见性传感器一样,但是在 react-native 中。我有一个包含多个项目的平面列表(每个项目都有不同的高度)。我想检测特定项目(比如第 5 个项目)是否进入视口以及何时退出
我有一个非常基本的模态组件(使用React-native-modal),它渲染给定的子视图。但是,我不希望出现类似于 KeyBoardAvoiding 视图的行为,即我不希望在键盘打开时向上推模式。
<Modal
isVisible={isVisible}
onBackdropPress={onCartDismiss}
style={CartStyles.cartModal}
onSwipeEnd={this.onCartDismiss}
onSwipe={this.onCartDismiss}
swipeDirection="down"
swipeThreshold={200}
propagateSwipe
avoidKeyboard={false}
>
{this.props.children}
....
Run Code Online (Sandbox Code Playgroud)
在 ios 上它工作正常,即键盘在模态组件上打开,但在 android 上则不然。voidKeyboard={false} 不起作用。
这是我的模式风格(位置:'绝对'也不起作用)
cartModal: {
position: 'absolute',
justifyContent: 'flex-end',
bottom: 0,
left: 0,
right: 0,
zIndex: 1,
},
Run Code Online (Sandbox Code Playgroud)
我什至尝试将 android 清单中的 softinputmode 更改为:
android:windowSoftInputMode="adjustPan"
Run Code Online (Sandbox Code Playgroud) 我在使用 Alamofire 对象映射器点击 Alamofire 获取请求时出错
这就是我如何使用 API-
APIService.shared.getSlots{ (success,weekSlots, error) in
if success {
self.weekSlots = weekSlots!
print("success!!")
} else {
print(error?.errorMessage ?? "NOPE")
}
}
Run Code Online (Sandbox Code Playgroud)
而 APIService 类中的 getSlot 函数是-
open func getSlots(completion: @escaping (Bool, [WeekSlot]?, APIError?) -> ()) {
sessionManager.request(APIRouter.getSlots())
.validate(statusCode: 200..<300)
.responseArray(queue: nil,
keyPath: "week_slots",
context: nil) { (response: DataResponse<[WeekSlot]>) in
switch response.result {
case .success(let value):
self.saveArraysToRealm(value: value)
completion(true,value, nil)
case .failure:
let error = self.processFailure(json: JSON(response.data as Any))
completion(false, nil, error)
print(error)
}
}
} …Run Code Online (Sandbox Code Playgroud) 我需要在视图上单击和双击执行不同的操作。双击时我需要喜欢该图像,就像 Instagram 双击体验一样。单击一次我需要打开一个模式。对于双击,我使用了 TapGestureHandler ,效果非常好
<TapGestureHandler
ref={this.doubleTapRef}
maxDelayMs={200}
onHandlerStateChange={this.onProductImageDoubleTap}
numberOfTaps={2}
>
<SomeChildComponent ...
Run Code Online (Sandbox Code Playgroud)
但是当我添加任何 Touchable 来检测单击时
<TouchableWithoutFeedback onPress={this.imageTapped}>
Run Code Online (Sandbox Code Playgroud)
双击该this.imageTapped函数会与 一起被调用两次this.onProductImageDoubleTap。当两次点击快速连续完成时,有什么方法可以取消对可触摸的点击
我刚开始使用 swiftui,但在 ui 对齐方面遇到了问题。以下代码从图像顶部创建一个空间
VStack(alignment: .leading) {
Image(item.imageUrl)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 72, height: 72, alignment: .top).padding(.top,0)
Text("\(item.name)").font(Font.system(size:12, design: .default))
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity).lineLimit(2)
}
}
Run Code Online (Sandbox Code Playgroud)
我可以看到 VStack 接受 param alignment,但它是水平对齐的。我需要的是图像应该粘在其超级视图的顶部。有没有办法在不使用 Spacer() 的情况下做到这一点。
就像在 react-native 中,我们曾经有 justifyContent 和 alignItems 用于子项的水平和垂直对齐。
更新:
文本或任何视图也存在同样的问题。例如此代码将两个文本放在视图的中心
VStack(alignment: .leading, spacing: 0) {
Text("line 1")
Text("line 2")
}
Run Code Online (Sandbox Code Playgroud)
VStack 中的参数对齐用于水平对齐。
现在要将这些文本对齐到顶部,我能想到的唯一方法是这样引入Spacer():
struct MyCustomView:View {
var body: some View {
VStack(alignment: .leading, spacing: 0) {
Text("line 1")
Text("line 2")
Spacer()
}
}
Run Code Online (Sandbox Code Playgroud)
这确实可以暂时解决问题:
但是间隔器会在复杂的视图中产生问题,假设另一个开发人员想要在我的视图下方添加一个自定义视图(本例中的第 3 …
目前我正在使用QuickLook模块从网络打开pdf,但它显示一个空白页面,错误"无法为网址发布文件扩展名:https://testing-xamidea.s3.amazonaws.com/flowchart/20171103182728150973368.pdf "在控制台.我猜QuickLook只能打开本地保存的Pdf文件.是否可以使用quicklook从网络加载pdf?.到目前为止这是我的代码 - {fileURL包含要加载pdf的url,也设置了委托等)
extension FlowchartVC:QLPreviewControllerDelegate,QLPreviewControllerDataSource {
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
return 1
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
let url : NSURL! = NSURL(string : fileURL)
return url
}
func previewControllerWillDismiss(_ controller: QLPreviewController) {
self.dismiss(animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud) 如何在React导航(3.x)中为全屏模式提供透明背景。此处给出的解决方案不适用于新版本的react-navigation。我想要新的全屏模式中的透明颜色,该颜色显示在另一个屏幕上。
const MainNavigator = createStackNavigator(
{
BrowserHome: { screen: BrowserHome },
ImageDetailModal: {
screen: ImageDetail,
navigationOptions: {
header: null
}
}
},
{
mode: "modal",
cardStyle: {
backgroundColor: "transparent",
opacity: 1
}
}
);
const AppContainer = createAppContainer(MainNavigator);
export default AppContainer;
Run Code Online (Sandbox Code Playgroud)
在“ BrowserHome”组件上显示的“图像细节”组件是:
export default class ImageDetail extends React.Component {
render() {
const modalColor = this.props.navigation.getParam("modalColor");
return (
<View
style={{ flex: 1, flexDirection: "column", justifyContent: "flex-end" }}
>
<View
style={{
height: "50%",
width: "100%",
backgroundColor: "red",
justifyContent: "center" …Run Code Online (Sandbox Code Playgroud) react-native ×5
ios ×4
swift ×2
xcode ×2
alamofire ×1
modal-dialog ×1
objectmapper ×1
quicklook ×1
swiftui ×1