今天检查了一些放大文档(我知道这个文档说它是iOS场景中的预览)但我遇到了一个障碍。
假设
Person并查询Amplify.APItype Person @model {
id: ID!
name: String!
possessions: [Thing] # list of things this person owns.
@connection(keyName: "byPerson", fields: ["id"])
}
type Thing @model
@key(name: "byPerson", fields: ["personId"]) {
id: ID!
name: String!
personId: ID!
ownerOfThings: Person # defining the 'belongsTo' property.
@connection(fields: ["personId"])
}
Run Code Online (Sandbox Code Playgroud)
这将生成以下代码:
type Person @model {
id: ID!
name: String!
possessions: [Thing] # list of things this person owns.
@connection(keyName: "byPerson", …Run Code Online (Sandbox Code Playgroud) 我正在编写一个消耗资源的库,无论出于什么原因,API的设计方式是在不同的线程上引发事件,但是必须在主线程上完成API的调用.
假设我尝试使用的API被定义为(我将省略事件定义):
public sealed class DodgyService
{
public void MethodThatHasToBeCalledOnTheMainThread() { ... }
}
Run Code Online (Sandbox Code Playgroud)
为了使用这个API,我在我的库中添加了一个名为Service(Yup,非常原始名称)的服务,它将创建一个新任务(当我指定一个已经创建的TaskScheduler时,它将在主线程上运行SynchronizationContext).
这是我的实现:
public class Service
{
private readonly TaskFactory _taskFactory;
private readonly TaskScheduler _mainThreadScheduler;
public Service(TaskFactory taskFactory, TaskScheduler mainThreadScheduler)
{
_taskFactory = taskFactory;
_mainThreadScheduler = mainThreadScheduler;
}
// Assume this method can be called from any thread.
// In this sample is called by the main thread but most of the time
// the caller will be running on a background thread.
public Task …Run Code Online (Sandbox Code Playgroud) 我的问题很具体:
如何链接两个动画,以便将项目从 X 移动到 Y,然后从 Y 移动到 Z?
我有一个视图,我想从位置 (x,y) 到 (x+a, y+b) 设置动画,然后让它“悬停”在那里。我以为动画会从它停止的点继续,但事实证明我错了......当它执行循环时,它从初始值(0,0)而不是最后一个位置重新开始。
// this is in my index.js
class App extends Component {
constructor(props) {
super(props);
this.translateValue = new Animated.ValueXY({x: 0, y: 0});
}
componentDidMount() {
Animated.sequence([
Animated.timing(this.translateValue,
{ toValue: { x: 30, y: 30 }, duration: 1000, easing: Easing.linear }),
Animated.loop(
Animated.sequence([
Animated.timing(this.translateValue,
{ toValue: { x: 30, y: 20 }, duration: 1000, easing: Easing.linear }),
Animated.timing(this.translateValue,
{ toValue: { x: 30, y: 30 }, duration: 1000, …Run Code Online (Sandbox Code Playgroud) 在这个问题被标记为另一个问题的重复之前,我试图了解发布者的工作方式,因为它以我不期望的方式行事。
使用与前面提到的问题的答案相同的示例:
// Let's define the view model with my view...
import Combine
import SwiftUI
class TimerViewModel: ObservableObject {
private let cancellable: AnyCancellable?
let intervalPublisher = Timer.TimerPublisher(
interval: 1.0,
runLoop: .main,
mode: .default)
init() {
self.cancellable = timerPublisher.connect() as? AnyCancellable
}
deinit {
self.cancellable?.cancel()
}
}
struct Clock : View {
@EnvironmentObject var viewModel: TimerViewModel
@State private var currentTime: String = "Initial"
var body: some View {
VStack {
Text(currentTime)
}
.onReceive(timer.intervalPublisher) { newTime in
self.currentTime = String(describing: …Run Code Online (Sandbox Code Playgroud) swift ×2
.net ×1
amplify-ios ×1
animation ×1
aws-amplify ×1
c# ×1
combine ×1
graphql ×1
ios ×1
javascript ×1
react-native ×1
swiftui ×1
xcode ×1
xcode11 ×1