From 3436364b27a0e490aa2d2d77559dd61d879cfada Mon Sep 17 00:00:00 2001 From: Jonathan Dong Date: Tue, 13 Nov 2018 15:09:05 +0800 Subject: [PATCH 01/20] [build] Updated the Apache release scripts. (#1741) Added 'npm run build:rax' to generate Rax precompiled js files, and updated the build command and generated project for iOS. --- scripts/build_from_source.sh | 12 ++++++++---- scripts/generate_apache_release.sh | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/build_from_source.sh b/scripts/build_from_source.sh index 0757d9e4ba..da380282c2 100755 --- a/scripts/build_from_source.sh +++ b/scripts/build_from_source.sh @@ -18,20 +18,22 @@ set -e if [ ! -f scripts/build_from_source.sh ];then - echo "This script must execute in project root" + echo "This script must be executed from project root." exit 1 fi -echo "Build Weex SDK From Source...." +echo "Build Weex SDK from source...." npm install npm run build:jsfm npm run build:polyfill +npm run build:rax echo "Weex JS Framework build completed." sleep 2 -mkdir pre-build +# Copy built JS resources to their destination. +[ -d pre-build ] || mkdir pre-build cp dist/weex-js-framework.min.js pre-build/native-bundle-main.js cp dist/weex-js-framework.min.js android_sdk/assets/native-bundle-main.js cp dist/weex-js-framework.min.js pre-build/weex-main-jsfm.js @@ -40,10 +42,12 @@ cp dist/weex-polyfill.min.js pre-build/weex-polyfill.js cp dist/weex-rax.min.js pre-build/weex-rax-api.js cp dist/weex-rax.min.js android_sdk/assets/weex-rax-api.js +# Build android_sdk gradle wrapper --gradle-version 4.4 echo 'include ":android_sdk"'>settings.gradle ./gradlew :android_sdk:assemble -PasfRelease -xcodebuild -project ios_sdk/WeexSDK.xcodeproj -target WeexSDK_MTL +# Build iOS sdk +xcodebuild -project ios_sdk/WeexSDK.xcodeproj -scheme WeexSDK_MTL echo "Weex SDK Build completed." diff --git a/scripts/generate_apache_release.sh b/scripts/generate_apache_release.sh index 9076513daf..d339337f20 100755 --- a/scripts/generate_apache_release.sh +++ b/scripts/generate_apache_release.sh @@ -32,9 +32,10 @@ rm -rf $dest/android/sdk/src/test/java/com mv $dest/ios/sdk $dest/ios_sdk mv $dest/android/sdk $dest/android_sdk -$SED_CMD -i '' 's/\.\.\/\.\.\/weex_core/\.\.\/weex_core/g' $dest/android_sdk/build.gradle +$SED_CMD -i '' 's/\.\.\/\.\.\/weex_core/\.\.\/weex_core/g' $dest/android_sdk/build.gradle $dest/ios_sdk/WeexSDK.xcodeproj/project.pbxproj $SED_CMD -i '' 's/\.\.\/\.\.\/pre-build/\.\.\/pre-build/g' $dest/android_sdk/build.gradle $dest/ios_sdk/WeexSDK.xcodeproj/project.pbxproj +[ -d "$dest/ios_sdk/build" ] && rm -rf "$dest/ios_sdk/build" mv $dest/android/build.gradle $dest/build.gradle rm -rf $dest/android $dest/ios -rm -rf $dest/android_sdk/gradle \ No newline at end of file +rm -rf $dest/android_sdk/gradle From 3b67c87aca09aa76d74881002e52d84877b795cc Mon Sep 17 00:00:00 2001 From: Jonathan Dong Date: Tue, 13 Nov 2018 15:26:26 +0800 Subject: [PATCH 02/20] [Release] Roll version number to 0.20.0 --- android/playground/app/build.gradle | 2 +- android/sdk/build.gradle | 2 +- ios/sdk/WeexSDK/Sources/Utility/WXDefine.h | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/android/playground/app/build.gradle b/android/playground/app/build.gradle index ba27f35f4f..6870572ef6 100755 --- a/android/playground/app/build.gradle +++ b/android/playground/app/build.gradle @@ -13,7 +13,7 @@ android { minSdkVersion project.minSdkVersion targetSdkVersion project.targetSdkVersion versionCode 17 - versionName "0.19.0" + versionName "0.20.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true ndk{ diff --git a/android/sdk/build.gradle b/android/sdk/build.gradle index 476d6736ac..3665675bba 100755 --- a/android/sdk/build.gradle +++ b/android/sdk/build.gradle @@ -36,7 +36,7 @@ checkstyle { } -version = "0.19.0.4" +version = "0.20.0" android { diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXDefine.h b/ios/sdk/WeexSDK/Sources/Utility/WXDefine.h index d58bb8318d..4dd1ab9ab6 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXDefine.h +++ b/ios/sdk/WeexSDK/Sources/Utility/WXDefine.h @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -20,7 +20,7 @@ #ifndef __WX_DEFINE_H__ #define __WX_DEFINE_H__ -#define WX_SDK_VERSION @"0.19.0" +#define WX_SDK_VERSION @"0.20.0" #if defined(__cplusplus) #define WX_EXTERN extern "C" __attribute__((visibility("default"))) @@ -125,8 +125,8 @@ parts = [parts subarrayWithRange:(NSRange){0, parts.count - 1}];\ #endif /** - * @abstract Compared with system version of current device - * + * @abstract Compared with system version of current device + * * @return YES if greater than or equal to the system verison, otherwise, NO. * */ From 7139ca29c8223083ca8b6c09994852f376dea530 Mon Sep 17 00:00:00 2001 From: Jonathan Dong Date: Wed, 14 Nov 2018 10:24:39 +0800 Subject: [PATCH 03/20] [Release] Added the missing Apache license (#1753) --- android/sdk/build.gradle | 19 ++++++++++ android/sdk/gradle.properties | 19 ++++++++++ android/sdk/proguard-rules.pro | 21 ++++++++++- android/sdk/publish.sh | 21 ++++++++++- weex_core/CMakeLists.txt | 18 +++++++++ weex_core/Source/CMakeLists.txt | 18 +++++++++ weex_core/Source/IPC/CMakeLists.txt | 19 ++++++++++ .../Source/core/data_render/class_factory.cc | 37 +++++++++++++------ .../Source/core/data_render/tokenizer.cc | 27 ++++++++++++-- .../Source/third_party/json11/CMakeLists.txt | 19 ++++++++++ weex_core/Source/weexjsc_version_script.txt | 18 +++++++++ weex_core/Source/wson/CMakeLists.txt | 19 ++++++++++ 12 files changed, 238 insertions(+), 17 deletions(-) diff --git a/android/sdk/build.gradle b/android/sdk/build.gradle index 3665675bba..85a6674f5b 100755 --- a/android/sdk/build.gradle +++ b/android/sdk/build.gradle @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + buildscript { dependencies { classpath 'com.android.tools.build:gradle:2.3.3' diff --git a/android/sdk/gradle.properties b/android/sdk/gradle.properties index 08b9d65cdf..c621f8c509 100755 --- a/android/sdk/gradle.properties +++ b/android/sdk/gradle.properties @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: diff --git a/android/sdk/proguard-rules.pro b/android/sdk/proguard-rules.pro index 73247bc730..957227f8c9 100755 --- a/android/sdk/proguard-rules.pro +++ b/android/sdk/proguard-rules.pro @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in /Users/ouy/Library/AndroidStudio/sdk/tools/proguard/proguard-android.txt @@ -19,4 +38,4 @@ -keep class com.taobao.weex.layout.** { *; } -keep class com.taobao.weex.WXSDKEngine { *; } -keep class com.taobao.weex.base.SystemMessageHandler { *; } --dontwarn com.taobao.weex.bridge.** \ No newline at end of file +-dontwarn com.taobao.weex.bridge.** diff --git a/android/sdk/publish.sh b/android/sdk/publish.sh index 4d70a7ce00..7700dd320b 100755 --- a/android/sdk/publish.sh +++ b/android/sdk/publish.sh @@ -1,2 +1,21 @@ #!/usr/bin/env bash -./gradlew clean assemble publish \ No newline at end of file + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +./gradlew clean assemble publish diff --git a/weex_core/CMakeLists.txt b/weex_core/CMakeLists.txt index 2894e59436..b0dfca0dcf 100644 --- a/weex_core/CMakeLists.txt +++ b/weex_core/CMakeLists.txt @@ -1,3 +1,21 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# cmake_minimum_required(VERSION 3.4.1) project(WeexCore) add_subdirectory(Source) diff --git a/weex_core/Source/CMakeLists.txt b/weex_core/Source/CMakeLists.txt index 8b9df20db5..92b84beec6 100644 --- a/weex_core/Source/CMakeLists.txt +++ b/weex_core/Source/CMakeLists.txt @@ -1,3 +1,21 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# cmake_minimum_required(VERSION 3.4.1) set(WEEXCORE_LIBRARY_NAME weexcore) diff --git a/weex_core/Source/IPC/CMakeLists.txt b/weex_core/Source/IPC/CMakeLists.txt index f95e0b395e..beb1551f58 100644 --- a/weex_core/Source/IPC/CMakeLists.txt +++ b/weex_core/Source/IPC/CMakeLists.txt @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + cmake_minimum_required(VERSION 3.4.1) set(IPC_LIBRARY_NAME weexipc) diff --git a/weex_core/Source/core/data_render/class_factory.cc b/weex_core/Source/core/data_render/class_factory.cc index bca5d9e8a8..4dccd81510 100644 --- a/weex_core/Source/core/data_render/class_factory.cc +++ b/weex_core/Source/core/data_render/class_factory.cc @@ -1,6 +1,21 @@ -// -// Created by chad on 2018/7/19. -// +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ #include "core/data_render/class_factory.h" #include "core/data_render/class.h" @@ -22,7 +37,7 @@ Value ClassFactory::CreateClassDescriptor(ClassDescriptor *p_super) { descs_.push_back(desc); return value; } - + Value ClassFactory::CreateArray() { Array *array = new Array(); Value value; @@ -31,7 +46,7 @@ Value ClassFactory::CreateArray() { arrays_.push_back(array); return value; } - + Value ClassFactory::CreateTable() { Table *table = new Table(); Value value; @@ -40,7 +55,7 @@ Value ClassFactory::CreateTable() { tables_.push_back(table); return value; } - + Value ClassFactory::ClassString() { ClassDescriptor *desc = NewClassString(); Value value; @@ -49,7 +64,7 @@ Value ClassFactory::ClassString() { descs_.push_back(desc); return value; } - + Value ClassFactory::ClassJSON() { ClassDescriptor *desc = NewClassJSON(); Value value; @@ -58,7 +73,7 @@ Value ClassFactory::ClassJSON() { descs_.push_back(desc); return value; } - + Value ClassFactory::ClassArray() { ClassDescriptor *desc = NewClassArray(); Value value; @@ -67,7 +82,7 @@ Value ClassFactory::ClassArray() { descs_.push_back(desc); return value; } - + Value ClassFactory::ClassObject() { ClassDescriptor *desc = NewClassOject(); Value value; @@ -76,7 +91,7 @@ Value ClassFactory::ClassObject() { descs_.push_back(desc); return value; } - + int ClassFactory::findDesc(const ClassDescriptor *desc) { int index = 0; for (auto d : descs_) { @@ -98,7 +113,7 @@ ClassInstance *ClassFactory::CreateClassInstanceFromSuper(ClassDescriptor *p_des } return inst; } - + Value ClassFactory::CreateClassInstance(ClassDescriptor *p_desc) { ClassInstance *inst = CreateClassInstanceFromSuper(p_desc); Value value; diff --git a/weex_core/Source/core/data_render/tokenizer.cc b/weex_core/Source/core/data_render/tokenizer.cc index a229196032..2d7ceec8e1 100644 --- a/weex_core/Source/core/data_render/tokenizer.cc +++ b/weex_core/Source/core/data_render/tokenizer.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include "core/data_render/tokenizer.h" #include "core/data_render/token.h" #include "core/data_render/scanner.h" @@ -16,12 +35,12 @@ namespace data_render { // TokenizerState implementation // ------------------------------- - + #ifdef __ANDROID__ #undef EOF static const char EOF = -1; #endif - + class TokenizerState { public: static std::unordered_map keywords; @@ -578,7 +597,7 @@ Token Tokenizer::ParseString(char delim) { } Token::Type type = delim == '`' ? Token::TEMPLATE : Token::STRING; - + if (utf8) { buffer = utf8_decode(buffer); } @@ -680,5 +699,5 @@ Token Tokenizer::ParseNumber(char start) { } } -} +} diff --git a/weex_core/Source/third_party/json11/CMakeLists.txt b/weex_core/Source/third_party/json11/CMakeLists.txt index 148c31ffed..0296ab309c 100644 --- a/weex_core/Source/third_party/json11/CMakeLists.txt +++ b/weex_core/Source/third_party/json11/CMakeLists.txt @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + cmake_minimum_required(VERSION 3.4.1) set(JSON11_LIBRARY_NAME json11) diff --git a/weex_core/Source/weexjsc_version_script.txt b/weex_core/Source/weexjsc_version_script.txt index c34fbfce6c..69a28ec88e 100644 --- a/weex_core/Source/weexjsc_version_script.txt +++ b/weex_core/Source/weexjsc_version_script.txt @@ -1,3 +1,21 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# { global: *Inject_GCanvasFunc*; Java_com*; JNI_OnLoad; JNI_OnUnload; local: *; diff --git a/weex_core/Source/wson/CMakeLists.txt b/weex_core/Source/wson/CMakeLists.txt index a331a391dd..e42d6c75c7 100644 --- a/weex_core/Source/wson/CMakeLists.txt +++ b/weex_core/Source/wson/CMakeLists.txt @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + cmake_minimum_required(VERSION 3.4.1) set(WSON_LIBRARY_NAME wson) From d8fb6650e8a2f8f87ba1641e4529ca7356f2ae0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=AB=E7=BB=AA=E6=97=BB?= Date: Thu, 15 Nov 2018 16:49:00 +0800 Subject: [PATCH 04/20] Update LICENSE (#1765) --- LICENSE | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 906f7b570a..931913ffd3 100644 --- a/LICENSE +++ b/LICENSE @@ -256,7 +256,8 @@ This product bundles chromium v66.0.3344.2, which is available under a "BSD-styl weex_core/Source/android/jniprebuild/jniheader/NativeRenderObjectUtils_jni.h weex_core/Source/android/jniprebuild/jniheader/SystemMessageHandler_jni.h weex_core/Source/android/jniprebuild/jniheader/WXBridge_jni.h - weex_core/Source/android/jniprebuild/jniheader/WXJsFunctions_jni.h + weex_core/Source/android/jniprebuild/jniheader/WXDebugJsBridge_jni.h + weex_core/Source/android/jniprebuild/jniheader/WXParams_jni.h weex_core/Source/android/jniprebuild/jni_generator.py This product bundles Android Open Source Project vandroid-4.2.2_r1, which is available under a "BSD" license. For details, see https://android.googlesource.com/platform/bionic/+/android-4.2.2_r1/libc/README and following files: From 03e203da9d573583bbd1450d87b8dcae25a1454b Mon Sep 17 00:00:00 2001 From: Douma Fang Date: Fri, 9 Nov 2018 16:37:39 +0800 Subject: [PATCH 05/20] [iOS] fix scrollEnd can not get offset (#1729) --- ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm index dfe8824891..a27820222b 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm @@ -903,7 +903,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL } if (!decelerate) { _isScrolling = NO; - [self performSelector:@selector(scrollViewDidEndDecelerating:) withObject:nil afterDelay:0.1]; + [self performSelector:@selector(scrollViewDidEndDecelerating:) withObject:scrollView afterDelay:0.1]; } NSHashTable *delegates = [_delegates copy]; From fef4326daa0d1ab43524e03836d95fcea75056ae Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Sat, 10 Nov 2018 22:54:57 +0800 Subject: [PATCH 06/20] [iOS] Remove specific animation by key instead of removing all. If we don' t remove, updating transform won't work after doing CAAnimation. http://dotwe.org/vue/ce7d8d3bd4e67d3fe321c9e8b0bbbb7b (#1734) --- ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m index 70a8feba25..75b09d8d01 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m +++ b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m @@ -123,7 +123,7 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag _animationInfo.target.view.layer.anchorPoint = _animationInfo.originAnchorPoint; _animationInfo.target.view.layer.frame = originFrame; } - [_animationInfo.target.layer removeAllAnimations]; + [_animationInfo.target.layer removeAnimationForKey:_animationInfo.propertyName]; if (_finishBlock) { _finishBlock(flag); From fabc9ae2a81c539c04f96758d0d5f4df36cf3889 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Wed, 14 Nov 2018 15:49:08 +0800 Subject: [PATCH 07/20] [iOS] Fix deadlock if WXSDKInstance is release in thread safe dictionary. (#1757) --- ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m | 13 ++----------- .../Utility/WXThreadSafeMutableDictionary.m | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m index 87bc32650b..613abd59a4 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m @@ -78,7 +78,6 @@ @implementation WXSDKInstance BOOL _debugJS; id _instanceJavaScriptContext; // sandbox javaScript context CGFloat _defaultPixelScaleFactor; - BOOL _bReleaseInstanceInMainThread; BOOL _defaultDataRender; } @@ -118,7 +117,6 @@ - (instancetype)init _apmInstance = [[WXApmForInstance alloc] init]; _defaultPixelScaleFactor = CGFLOAT_MIN; - _bReleaseInstanceInMainThread = YES; _defaultDataRender = NO; [self addObservers]; @@ -443,9 +441,6 @@ - (BOOL)_handleConfigCenter BOOL useJSCApiForCreateInstance = [[configCenter configForKey:@"iOS_weex_ext_config.useJSCApiForCreateInstance" defaultValue:@(YES) isDefault:NULL] boolValue]; [WXUtility setUseJSCApiForCreateInstance:useJSCApiForCreateInstance]; - - //Reading config from orange for Release instance in Main Thread or not - _bReleaseInstanceInMainThread = [[configCenter configForKey:@"iOS_weex_ext_config.releaseInstanceInMainThread" defaultValue:@(YES) isDefault:nil] boolValue]; BOOL shoudMultiContext = NO; shoudMultiContext = [[configCenter configForKey:@"iOS_weex_ext_config.createInstanceUsingMutliContext" defaultValue:@(YES) isDefault:NULL] boolValue]; @@ -659,13 +654,9 @@ - (void)destroyInstance [WXCoreBridge closePage:instanceId]; // Reading config from orange for Release instance in Main Thread or not, for Bug #15172691 +{ - if (!_bReleaseInstanceInMainThread) { + dispatch_async(dispatch_get_main_queue(), ^{ [WXSDKManager removeInstanceforID:instanceId]; - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - [WXSDKManager removeInstanceforID:instanceId]; - }); - } + }); //+} }); diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m b/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m index 3c32292269..6f31fb990e 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m @@ -145,24 +145,30 @@ - (NSEnumerator *)keyEnumerator - (void)setObject:(id)anObject forKey:(id)aKey { + id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); + originalObject = [_dict objectForKey:aKey]; [_dict setObject:anObject forKey:aKey]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + originalObject = nil; } - (void)setObject:(id)anObject forKeyedSubscript:(id )key { + id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); + originalObject = [_dict objectForKey:key]; [_dict setObject:anObject forKeyedSubscript:key]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + originalObject = nil; } - (NSArray *)allKeys @@ -189,24 +195,32 @@ - (NSArray *)allValues - (void)removeObjectForKey:(id)aKey { + id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); - [_dict removeObjectForKey:aKey]; + originalObject = [_dict objectForKey:aKey]; + if (originalObject) { + [_dict removeObjectForKey:aKey]; + } } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + originalObject = nil; } - (void)removeAllObjects { + NSArray* allValues = nil; // make sure that objects are not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); + allValues = [_dict allValues]; [_dict removeAllObjects]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + allValues = nil; } - (id)copy From 6ef7d464a9c7d6aafaee63b7bf97a1ef6084ac99 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Wed, 14 Nov 2018 18:53:06 +0800 Subject: [PATCH 08/20] [iOS] Trigger vsync on iOS in every batch. (#1759) --- weex_core/Source/core/render/page/render_page.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/weex_core/Source/core/render/page/render_page.cpp b/weex_core/Source/core/render/page/render_page.cpp index 032a0d7aa0..119af879ec 100644 --- a/weex_core/Source/core/render/page/render_page.cpp +++ b/weex_core/Source/core/render/page/render_page.cpp @@ -628,13 +628,11 @@ void RenderPage::Batch() { if ((kUseVSync && this->need_layout_.load()) || !kUseVSync) { LayoutInner(); } - else { #if OS_IOS - // vsync may stopped, trigger once - RenderAction *action = new RenderActionTriggerVSync(page_id()); - PostRenderAction(action); + // vsync may stopped, trigger once + RenderAction *action = new RenderActionTriggerVSync(page_id()); + PostRenderAction(action); #endif - } } RenderObject *RenderPage::GetRenderObject(const std::string &ref) { From 94049e9a014e48957e85699b4008b8fb4d41de10 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Mon, 19 Nov 2018 19:29:29 +0800 Subject: [PATCH 09/20] [iOS] Add completion callback for registerService (#1776) --- ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h | 30 ++++++++++++++++++- ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 17 +++++++++-- .../WeexSDK/Sources/Manager/WXBridgeManager.h | 7 +++-- .../WeexSDK/Sources/Manager/WXBridgeManager.m | 26 ++++++++++++---- 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h index 5e7b1e7db6..ac014a5781 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h @@ -82,6 +82,20 @@ */ + (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options; +/** + * @abstract Registers a component for a given name, options and js code + * + * @param name The service name to register + * + * @param options The service options to register + * + * @param serviceScript service js code to invoke + * + * @param completion Completion callback. JS is executed in asynchronously. + * + */ ++ (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; + /** * @abstract Registers a component for a given name, options and js url * @@ -92,7 +106,21 @@ * @param serviceScriptUrl The service url to register * */ -+ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl WithOptions:(NSDictionary *)options; ++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options; + +/** + * @abstract Registers a component for a given name, options and js url + * + * @param name The service name to register + * + * @param options The service options to register + * + * @param serviceScriptUrl The service url to register + * + * @param completion Completion callback. JS is executed in asynchronously. + * + */ ++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; /** * @abstract Registers a component for a given name, options and js code diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m index b5d7e00825..26ca8b7714 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m @@ -166,14 +166,25 @@ + (void)registerComponent:(NSString *)name withClass:(Class)clazz withProperties # pragma mark Service Register + + (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options { - [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options]; + [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options completion:nil]; +} + ++ (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion +{ + [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options completion:completion]; +} + ++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options +{ + [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options completion:nil]; } -+ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl WithOptions:(NSDictionary *)options ++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion { - [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options]; + [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options completion:completion]; } + (void)unregisterService:(NSString *)name diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h index 3d062774b7..8728161254 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h +++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h @@ -102,8 +102,9 @@ extern void WXPerformBlockOnBridgeThread(void (^block)(void)); * @param name : service name * @param serviceScript : script code * @param options : service options + * @param completion : completion callback **/ -- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options; +- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; /** @@ -111,9 +112,9 @@ extern void WXPerformBlockOnBridgeThread(void (^block)(void)); * @param name : service name * @param serviceScriptUrl : script url * @param options : service options + * @param completion : completion callback **/ - --(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options; +-(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; /** * Unregister JS service Script diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m index a0e8e4e2a2..f5c7a47e7d 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m @@ -288,28 +288,41 @@ - (JSValue *)callJSMethodWithResult:(WXCallJSMethod *)method return value; } --(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options +- (void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion { - if (!name || !serviceScriptUrl || !options) return; + if (!name || !serviceScriptUrl || !options) { + if (completion) { + completion(NO); + } + return; + } __weak typeof(self) weakSelf = self; WXResourceRequest *request = [WXResourceRequest requestWithURL:serviceScriptUrl resourceType:WXResourceTypeServiceBundle referrer:@"" cachePolicy:NSURLRequestUseProtocolCachePolicy]; WXResourceLoader *serviceBundleLoader = [[WXResourceLoader alloc] initWithRequest:request];; serviceBundleLoader.onFinished = ^(WXResourceResponse *response, NSData *data) { __strong typeof(weakSelf) strongSelf = weakSelf; NSString *jsServiceString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - [strongSelf registerService:name withService:jsServiceString withOptions:options]; + [strongSelf registerService:name withService:jsServiceString withOptions:options completion:completion]; }; serviceBundleLoader.onFailed = ^(NSError *loadError) { WXLogError(@"No script URL found"); + if (completion) { + completion(NO); + } }; [serviceBundleLoader start]; } -- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options +- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion { - if (!name || !serviceScript || !options) return; + if (!name || !serviceScript || !options) { + if (completion) { + completion(NO); + } + return; + } NSString *script = [WXServiceFactory registerServiceScript:name withRawScript:serviceScript withOptions:options]; @@ -318,6 +331,9 @@ - (void)registerService:(NSString *)name withService:(NSString *)serviceScript w // save it when execute [WXDebugTool cacheJsService:name withScript:serviceScript withOptions:options]; [weakSelf.bridgeCtx executeJsService:script withName:name]; + if (completion) { + completion(YES); + } }); } From b56ce0a4386b73305b87159666a7ee0e5a741831 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Tue, 20 Nov 2018 13:31:31 +0800 Subject: [PATCH 10/20] [iOS] Forbid adjustment of safeArea by system for cycle slider component. (#1780) --- ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm index 402e592c7a..ab26bc3655 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm @@ -73,6 +73,9 @@ - (id)initWithFrame:(CGRect)frame _currentIndex = 0; _itemViews = [[NSMutableArray alloc] init]; _scrollView = [[WXRecycleSliderScrollView alloc] init]; + if (@available(iOS 11.0, *)) { + _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; + } _scrollView.backgroundColor = [UIColor clearColor]; _scrollView.delegate = self; _scrollView.showsHorizontalScrollIndicator = NO; From aa88ab0c8edef22f84819ecd5ec380cf37fde117 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Wed, 21 Nov 2018 13:11:22 +0800 Subject: [PATCH 11/20] [iOS] Add methods to retrieve css style values from weexcore c++ object. --- .../Sources/Layout/WXComponent+Layout.h | 72 ++++++++++++++++- .../Sources/Layout/WXComponent+Layout.mm | 80 +++++++++++++++++++ weex_core/Source/core/layout/flex_enum.h | 8 +- weex_core/Source/core/layout/layout.h | 2 +- 4 files changed, 158 insertions(+), 4 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h index a33884769c..7a7dc37ff7 100644 --- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h +++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h @@ -26,6 +26,13 @@ #ifdef __cplusplus #include "layout.h" +typedef WeexCore::WXCoreFlexDirection WXCoreFlexDirection; +typedef WeexCore::WXCoreFlexWrap WXCoreFlexWrap; +typedef WeexCore::WXCoreJustifyContent WXCoreJustifyContent; +typedef WeexCore::WXCoreAlignItems WXCoreAlignItems; +typedef WeexCore::WXCoreAlignSelf WXCoreAlignSelf; +typedef WeexCore::WXCorePositionType WXCorePositionType; + extern "C" { #endif bool flexIsUndefined(float value); @@ -33,6 +40,19 @@ extern "C" { } #endif +#ifndef __cplusplus +// Ensure that .m files can use css style enum definitions. +#include "flex_enum.h" + +typedef enum WXCoreFlexDirection WXCoreFlexDirection; +typedef enum WXCoreFlexWrap WXCoreFlexWrap; +typedef enum WXCoreJustifyContent WXCoreJustifyContent; +typedef enum WXCoreAlignItems WXCoreAlignItems; +typedef enum WXCoreAlignSelf WXCoreAlignSelf; +typedef enum WXCorePositionType WXCorePositionType; + +#endif + @interface WXComponent () { @package @@ -51,9 +71,59 @@ extern "C" { * @warning Subclasses must not override this. */ #ifdef __cplusplus -@property(nonatomic, readonly, assign) WeexCore::WXCoreLayoutNode *flexCssNode; +@property (nonatomic, readonly, assign) WeexCore::WXCoreLayoutNode *flexCssNode; #endif +/** + * @abstract Get css style value for key. The key should be of CSS standard form. + * This method is for convenience use in C/ObjC environment. And if you want to + * retrieve all style values or in C++, you could use flexCssNode directly. + * + * Thread usage: + * This method should be invoked in component thread by WXPerformBlockOnComponentThread. + * Note that all initWithRef methods of WXComponent and its subclasses are performed in + * component thread by default. Therefore you can call this method directly in initWithRef. + * + * Supported keys: + * width, height, min-width, min-height, max-width, max-height, + * margin-(left/right/top/bottom) + * padding-(left/right/top/bottom) + * border-(left/right/top/bottom)-width + * left, right, top, bottom + * flex-grow + */ +- (float)getCssStyleValueForKey:(NSString *)key; + +/** + * @abstract Get css style flex-direction. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCoreFlexDirection)getCssStyleFlexDirection; + +/** + * @abstract Get css style flex-wrap. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCoreFlexWrap)getCssStyleFlexWrap; + +/** + * @abstract Get css style justify-content. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCoreJustifyContent)getCssStyleJustifyContent; + +/** + * @abstract Get css style align-items. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCoreAlignItems)getCssStyleAlignItems; + +/** + * @abstract Get css style align-self. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCoreAlignSelf)getCssStyleAlignSelf; + +/** + * @abstract Get css style position. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCorePositionType)getCssStylePositionType; + /** * @abstract Convert layout dimension value like 'left', 'width' to style value in js considering viewport and scale. */ diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm index 18cb24dbb1..8afd225d18 100644 --- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm +++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm @@ -366,6 +366,86 @@ - (CGFloat)judgePropValuePropValue:(id)propValue defaultValue:(CGFloat)defaultVa return defaultValue; } +- (float)getCssStyleValueForKey:(NSString *)key +{ + /* + * width, height, min-width, min-height, max-width, max-height, + * margin-(left/right/top/bottom) + * padding-(left/right/top/bottom) + * border-(left/right/top/bottom)-width + * left, right, top, bottom + * flex-grow + */ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + if (_flexCssNode == nullptr) { + return NAN; + } + + std::string ckey = [key UTF8String]; + if (ckey == "width") return _flexCssNode->getStyleWidth(); + if (ckey == "height") return _flexCssNode->getStyleHeight(); + if (ckey == "min-width") return _flexCssNode->getMinWidth(); + if (ckey == "min-height") return _flexCssNode->getMinHeight(); + if (ckey == "max-width") return _flexCssNode->getMaxWidth(); + if (ckey == "max-height") return _flexCssNode->getMaxHeight(); + if (ckey == "margin-left") return _flexCssNode->getMarginLeft(); + if (ckey == "margin-right") return _flexCssNode->getMarginRight(); + if (ckey == "margin-top") return _flexCssNode->getMarginTop(); + if (ckey == "margin-bottom") return _flexCssNode->getMarginBottom(); + if (ckey == "padding-left") return _flexCssNode->getPaddingLeft(); + if (ckey == "padding-right") return _flexCssNode->getPaddingRight(); + if (ckey == "padding-top") return _flexCssNode->getPaddingTop(); + if (ckey == "padding-bottom") return _flexCssNode->getPaddingBottom(); + if (ckey == "border-left-width") return _flexCssNode->getBorderWidthLeft(); + if (ckey == "border-right-width") return _flexCssNode->getBorderWidthRight(); + if (ckey == "border-top-width") return _flexCssNode->getBorderWidthTop(); + if (ckey == "border-bottom-width") return _flexCssNode->getBorderWidthBottom(); + if (ckey == "left") return _flexCssNode->getStylePositionLeft(); + if (ckey == "right") return _flexCssNode->getStylePositionRight(); + if (ckey == "top") return _flexCssNode->getStylePositionTop(); + if (ckey == "bottom") return _flexCssNode->getStylePositionBottom(); + if (ckey == "flex-grow") return _flexCssNode->getFlex(); + + WXAssert(NO, @"Invalid css style key %@", key); + return NAN; +} + +- (WXCoreFlexDirection)getCssStyleFlexDirection +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getFlexDirection() : kFlexDirectionColumn; +} + +- (WXCoreFlexWrap)getCssStyleFlexWrap +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getFlexWrap() : kNoWrap; +} + +- (WXCoreJustifyContent)getCssStyleJustifyContent +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getJustifyContent() : kJustifyFlexStart; +} + +- (WXCoreAlignItems)getCssStyleAlignItems +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getAlignItems() : kAlignItemsStretch; +} + +- (WXCoreAlignSelf)getCssStyleAlignSelf +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getAlignSelf() : kAlignSelfAuto; +} + +- (WXCorePositionType)getCssStylePositionType +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getStylePositionType() : kRelative; +} + - (NSString*)convertLayoutValueToStyleValue:(NSString*)valueName { if (_flexCssNode == nullptr) { diff --git a/weex_core/Source/core/layout/flex_enum.h b/weex_core/Source/core/layout/flex_enum.h index 9eb3676354..7e439b21ed 100644 --- a/weex_core/Source/core/layout/flex_enum.h +++ b/weex_core/Source/core/layout/flex_enum.h @@ -16,12 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -#ifdef __cplusplus #ifndef WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H #define WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H +/* These enum definitions may also be used by C files. */ +#ifdef __cplusplus namespace WeexCore { +#endif /** * MainAxis direction @@ -120,6 +122,8 @@ namespace WeexCore { kLeft, }; +#ifdef __cplusplus } +#endif + #endif //WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H -#endif \ No newline at end of file diff --git a/weex_core/Source/core/layout/layout.h b/weex_core/Source/core/layout/layout.h index 0d62edd1df..4b8f0c54df 100644 --- a/weex_core/Source/core/layout/layout.h +++ b/weex_core/Source/core/layout/layout.h @@ -836,7 +836,7 @@ namespace WeexCore { } } - inline WXCorePositionType getStypePositionType() const { + inline WXCorePositionType getStylePositionType() const { return mCssStyle->mPositionType; } From b79bb7c47d1c19dd2f449f89008c46f70150c4cb Mon Sep 17 00:00:00 2001 From: Jonathan Dong Date: Wed, 21 Nov 2018 15:53:33 +0800 Subject: [PATCH 12/20] Revert "Fix rc 0.20" --- .../Component/WXCycleSliderComponent.mm | 3 - .../Sources/Component/WXScrollerComponent.mm | 2 +- ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h | 30 +------ ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 17 +--- .../Sources/Layout/WXComponent+Layout.h | 72 +---------------- .../Sources/Layout/WXComponent+Layout.mm | 80 ------------------- .../WeexSDK/Sources/Manager/WXBridgeManager.h | 7 +- .../WeexSDK/Sources/Manager/WXBridgeManager.m | 26 ++---- ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m | 13 ++- .../Sources/Module/WXAnimationModule.m | 2 +- .../Utility/WXThreadSafeMutableDictionary.m | 16 +--- weex_core/Source/core/layout/flex_enum.h | 8 +- weex_core/Source/core/layout/layout.h | 2 +- .../Source/core/render/page/render_page.cpp | 8 +- 14 files changed, 35 insertions(+), 251 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm index ab26bc3655..402e592c7a 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm @@ -73,9 +73,6 @@ - (id)initWithFrame:(CGRect)frame _currentIndex = 0; _itemViews = [[NSMutableArray alloc] init]; _scrollView = [[WXRecycleSliderScrollView alloc] init]; - if (@available(iOS 11.0, *)) { - _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; - } _scrollView.backgroundColor = [UIColor clearColor]; _scrollView.delegate = self; _scrollView.showsHorizontalScrollIndicator = NO; diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm index a27820222b..dfe8824891 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm @@ -903,7 +903,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL } if (!decelerate) { _isScrolling = NO; - [self performSelector:@selector(scrollViewDidEndDecelerating:) withObject:scrollView afterDelay:0.1]; + [self performSelector:@selector(scrollViewDidEndDecelerating:) withObject:nil afterDelay:0.1]; } NSHashTable *delegates = [_delegates copy]; diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h index ac014a5781..5e7b1e7db6 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h @@ -82,20 +82,6 @@ */ + (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options; -/** - * @abstract Registers a component for a given name, options and js code - * - * @param name The service name to register - * - * @param options The service options to register - * - * @param serviceScript service js code to invoke - * - * @param completion Completion callback. JS is executed in asynchronously. - * - */ -+ (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; - /** * @abstract Registers a component for a given name, options and js url * @@ -106,21 +92,7 @@ * @param serviceScriptUrl The service url to register * */ -+ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options; - -/** - * @abstract Registers a component for a given name, options and js url - * - * @param name The service name to register - * - * @param options The service options to register - * - * @param serviceScriptUrl The service url to register - * - * @param completion Completion callback. JS is executed in asynchronously. - * - */ -+ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; ++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl WithOptions:(NSDictionary *)options; /** * @abstract Registers a component for a given name, options and js code diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m index 26ca8b7714..b5d7e00825 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m @@ -166,25 +166,14 @@ + (void)registerComponent:(NSString *)name withClass:(Class)clazz withProperties # pragma mark Service Register - + (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options { - [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options completion:nil]; -} - -+ (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion -{ - [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options completion:completion]; -} - -+ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options -{ - [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options completion:nil]; + [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options]; } -+ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion ++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl WithOptions:(NSDictionary *)options { - [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options completion:completion]; + [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options]; } + (void)unregisterService:(NSString *)name diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h index 7a7dc37ff7..a33884769c 100644 --- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h +++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h @@ -26,13 +26,6 @@ #ifdef __cplusplus #include "layout.h" -typedef WeexCore::WXCoreFlexDirection WXCoreFlexDirection; -typedef WeexCore::WXCoreFlexWrap WXCoreFlexWrap; -typedef WeexCore::WXCoreJustifyContent WXCoreJustifyContent; -typedef WeexCore::WXCoreAlignItems WXCoreAlignItems; -typedef WeexCore::WXCoreAlignSelf WXCoreAlignSelf; -typedef WeexCore::WXCorePositionType WXCorePositionType; - extern "C" { #endif bool flexIsUndefined(float value); @@ -40,19 +33,6 @@ extern "C" { } #endif -#ifndef __cplusplus -// Ensure that .m files can use css style enum definitions. -#include "flex_enum.h" - -typedef enum WXCoreFlexDirection WXCoreFlexDirection; -typedef enum WXCoreFlexWrap WXCoreFlexWrap; -typedef enum WXCoreJustifyContent WXCoreJustifyContent; -typedef enum WXCoreAlignItems WXCoreAlignItems; -typedef enum WXCoreAlignSelf WXCoreAlignSelf; -typedef enum WXCorePositionType WXCorePositionType; - -#endif - @interface WXComponent () { @package @@ -71,59 +51,9 @@ typedef enum WXCorePositionType WXCorePositionType; * @warning Subclasses must not override this. */ #ifdef __cplusplus -@property (nonatomic, readonly, assign) WeexCore::WXCoreLayoutNode *flexCssNode; +@property(nonatomic, readonly, assign) WeexCore::WXCoreLayoutNode *flexCssNode; #endif -/** - * @abstract Get css style value for key. The key should be of CSS standard form. - * This method is for convenience use in C/ObjC environment. And if you want to - * retrieve all style values or in C++, you could use flexCssNode directly. - * - * Thread usage: - * This method should be invoked in component thread by WXPerformBlockOnComponentThread. - * Note that all initWithRef methods of WXComponent and its subclasses are performed in - * component thread by default. Therefore you can call this method directly in initWithRef. - * - * Supported keys: - * width, height, min-width, min-height, max-width, max-height, - * margin-(left/right/top/bottom) - * padding-(left/right/top/bottom) - * border-(left/right/top/bottom)-width - * left, right, top, bottom - * flex-grow - */ -- (float)getCssStyleValueForKey:(NSString *)key; - -/** - * @abstract Get css style flex-direction. Thread usage the same as getCssStyleValueForKey. - */ -- (WXCoreFlexDirection)getCssStyleFlexDirection; - -/** - * @abstract Get css style flex-wrap. Thread usage the same as getCssStyleValueForKey. - */ -- (WXCoreFlexWrap)getCssStyleFlexWrap; - -/** - * @abstract Get css style justify-content. Thread usage the same as getCssStyleValueForKey. - */ -- (WXCoreJustifyContent)getCssStyleJustifyContent; - -/** - * @abstract Get css style align-items. Thread usage the same as getCssStyleValueForKey. - */ -- (WXCoreAlignItems)getCssStyleAlignItems; - -/** - * @abstract Get css style align-self. Thread usage the same as getCssStyleValueForKey. - */ -- (WXCoreAlignSelf)getCssStyleAlignSelf; - -/** - * @abstract Get css style position. Thread usage the same as getCssStyleValueForKey. - */ -- (WXCorePositionType)getCssStylePositionType; - /** * @abstract Convert layout dimension value like 'left', 'width' to style value in js considering viewport and scale. */ diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm index 8afd225d18..18cb24dbb1 100644 --- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm +++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm @@ -366,86 +366,6 @@ - (CGFloat)judgePropValuePropValue:(id)propValue defaultValue:(CGFloat)defaultVa return defaultValue; } -- (float)getCssStyleValueForKey:(NSString *)key -{ - /* - * width, height, min-width, min-height, max-width, max-height, - * margin-(left/right/top/bottom) - * padding-(left/right/top/bottom) - * border-(left/right/top/bottom)-width - * left, right, top, bottom - * flex-grow - */ - WXAssert(_flexCssNode != nullptr, @"Css node is null."); - if (_flexCssNode == nullptr) { - return NAN; - } - - std::string ckey = [key UTF8String]; - if (ckey == "width") return _flexCssNode->getStyleWidth(); - if (ckey == "height") return _flexCssNode->getStyleHeight(); - if (ckey == "min-width") return _flexCssNode->getMinWidth(); - if (ckey == "min-height") return _flexCssNode->getMinHeight(); - if (ckey == "max-width") return _flexCssNode->getMaxWidth(); - if (ckey == "max-height") return _flexCssNode->getMaxHeight(); - if (ckey == "margin-left") return _flexCssNode->getMarginLeft(); - if (ckey == "margin-right") return _flexCssNode->getMarginRight(); - if (ckey == "margin-top") return _flexCssNode->getMarginTop(); - if (ckey == "margin-bottom") return _flexCssNode->getMarginBottom(); - if (ckey == "padding-left") return _flexCssNode->getPaddingLeft(); - if (ckey == "padding-right") return _flexCssNode->getPaddingRight(); - if (ckey == "padding-top") return _flexCssNode->getPaddingTop(); - if (ckey == "padding-bottom") return _flexCssNode->getPaddingBottom(); - if (ckey == "border-left-width") return _flexCssNode->getBorderWidthLeft(); - if (ckey == "border-right-width") return _flexCssNode->getBorderWidthRight(); - if (ckey == "border-top-width") return _flexCssNode->getBorderWidthTop(); - if (ckey == "border-bottom-width") return _flexCssNode->getBorderWidthBottom(); - if (ckey == "left") return _flexCssNode->getStylePositionLeft(); - if (ckey == "right") return _flexCssNode->getStylePositionRight(); - if (ckey == "top") return _flexCssNode->getStylePositionTop(); - if (ckey == "bottom") return _flexCssNode->getStylePositionBottom(); - if (ckey == "flex-grow") return _flexCssNode->getFlex(); - - WXAssert(NO, @"Invalid css style key %@", key); - return NAN; -} - -- (WXCoreFlexDirection)getCssStyleFlexDirection -{ - WXAssert(_flexCssNode != nullptr, @"Css node is null."); - return _flexCssNode ? _flexCssNode->getFlexDirection() : kFlexDirectionColumn; -} - -- (WXCoreFlexWrap)getCssStyleFlexWrap -{ - WXAssert(_flexCssNode != nullptr, @"Css node is null."); - return _flexCssNode ? _flexCssNode->getFlexWrap() : kNoWrap; -} - -- (WXCoreJustifyContent)getCssStyleJustifyContent -{ - WXAssert(_flexCssNode != nullptr, @"Css node is null."); - return _flexCssNode ? _flexCssNode->getJustifyContent() : kJustifyFlexStart; -} - -- (WXCoreAlignItems)getCssStyleAlignItems -{ - WXAssert(_flexCssNode != nullptr, @"Css node is null."); - return _flexCssNode ? _flexCssNode->getAlignItems() : kAlignItemsStretch; -} - -- (WXCoreAlignSelf)getCssStyleAlignSelf -{ - WXAssert(_flexCssNode != nullptr, @"Css node is null."); - return _flexCssNode ? _flexCssNode->getAlignSelf() : kAlignSelfAuto; -} - -- (WXCorePositionType)getCssStylePositionType -{ - WXAssert(_flexCssNode != nullptr, @"Css node is null."); - return _flexCssNode ? _flexCssNode->getStylePositionType() : kRelative; -} - - (NSString*)convertLayoutValueToStyleValue:(NSString*)valueName { if (_flexCssNode == nullptr) { diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h index 8728161254..3d062774b7 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h +++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h @@ -102,9 +102,8 @@ extern void WXPerformBlockOnBridgeThread(void (^block)(void)); * @param name : service name * @param serviceScript : script code * @param options : service options - * @param completion : completion callback **/ -- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; +- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options; /** @@ -112,9 +111,9 @@ extern void WXPerformBlockOnBridgeThread(void (^block)(void)); * @param name : service name * @param serviceScriptUrl : script url * @param options : service options - * @param completion : completion callback **/ --(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; + +-(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options; /** * Unregister JS service Script diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m index f5c7a47e7d..a0e8e4e2a2 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m @@ -288,41 +288,28 @@ - (JSValue *)callJSMethodWithResult:(WXCallJSMethod *)method return value; } -- (void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion +-(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options { - if (!name || !serviceScriptUrl || !options) { - if (completion) { - completion(NO); - } - return; - } + if (!name || !serviceScriptUrl || !options) return; __weak typeof(self) weakSelf = self; WXResourceRequest *request = [WXResourceRequest requestWithURL:serviceScriptUrl resourceType:WXResourceTypeServiceBundle referrer:@"" cachePolicy:NSURLRequestUseProtocolCachePolicy]; WXResourceLoader *serviceBundleLoader = [[WXResourceLoader alloc] initWithRequest:request];; serviceBundleLoader.onFinished = ^(WXResourceResponse *response, NSData *data) { __strong typeof(weakSelf) strongSelf = weakSelf; NSString *jsServiceString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - [strongSelf registerService:name withService:jsServiceString withOptions:options completion:completion]; + [strongSelf registerService:name withService:jsServiceString withOptions:options]; }; serviceBundleLoader.onFailed = ^(NSError *loadError) { WXLogError(@"No script URL found"); - if (completion) { - completion(NO); - } }; [serviceBundleLoader start]; } -- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion +- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options { - if (!name || !serviceScript || !options) { - if (completion) { - completion(NO); - } - return; - } + if (!name || !serviceScript || !options) return; NSString *script = [WXServiceFactory registerServiceScript:name withRawScript:serviceScript withOptions:options]; @@ -331,9 +318,6 @@ - (void)registerService:(NSString *)name withService:(NSString *)serviceScript w // save it when execute [WXDebugTool cacheJsService:name withScript:serviceScript withOptions:options]; [weakSelf.bridgeCtx executeJsService:script withName:name]; - if (completion) { - completion(YES); - } }); } diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m index 613abd59a4..87bc32650b 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m @@ -78,6 +78,7 @@ @implementation WXSDKInstance BOOL _debugJS; id _instanceJavaScriptContext; // sandbox javaScript context CGFloat _defaultPixelScaleFactor; + BOOL _bReleaseInstanceInMainThread; BOOL _defaultDataRender; } @@ -117,6 +118,7 @@ - (instancetype)init _apmInstance = [[WXApmForInstance alloc] init]; _defaultPixelScaleFactor = CGFLOAT_MIN; + _bReleaseInstanceInMainThread = YES; _defaultDataRender = NO; [self addObservers]; @@ -441,6 +443,9 @@ - (BOOL)_handleConfigCenter BOOL useJSCApiForCreateInstance = [[configCenter configForKey:@"iOS_weex_ext_config.useJSCApiForCreateInstance" defaultValue:@(YES) isDefault:NULL] boolValue]; [WXUtility setUseJSCApiForCreateInstance:useJSCApiForCreateInstance]; + + //Reading config from orange for Release instance in Main Thread or not + _bReleaseInstanceInMainThread = [[configCenter configForKey:@"iOS_weex_ext_config.releaseInstanceInMainThread" defaultValue:@(YES) isDefault:nil] boolValue]; BOOL shoudMultiContext = NO; shoudMultiContext = [[configCenter configForKey:@"iOS_weex_ext_config.createInstanceUsingMutliContext" defaultValue:@(YES) isDefault:NULL] boolValue]; @@ -654,9 +659,13 @@ - (void)destroyInstance [WXCoreBridge closePage:instanceId]; // Reading config from orange for Release instance in Main Thread or not, for Bug #15172691 +{ - dispatch_async(dispatch_get_main_queue(), ^{ + if (!_bReleaseInstanceInMainThread) { [WXSDKManager removeInstanceforID:instanceId]; - }); + } else { + dispatch_async(dispatch_get_main_queue(), ^{ + [WXSDKManager removeInstanceforID:instanceId]; + }); + } //+} }); diff --git a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m index 75b09d8d01..70a8feba25 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m +++ b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m @@ -123,7 +123,7 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag _animationInfo.target.view.layer.anchorPoint = _animationInfo.originAnchorPoint; _animationInfo.target.view.layer.frame = originFrame; } - [_animationInfo.target.layer removeAnimationForKey:_animationInfo.propertyName]; + [_animationInfo.target.layer removeAllAnimations]; if (_finishBlock) { _finishBlock(flag); diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m b/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m index 6f31fb990e..3c32292269 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m @@ -145,30 +145,24 @@ - (NSEnumerator *)keyEnumerator - (void)setObject:(id)anObject forKey:(id)aKey { - id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); - originalObject = [_dict objectForKey:aKey]; [_dict setObject:anObject forKey:aKey]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } - originalObject = nil; } - (void)setObject:(id)anObject forKeyedSubscript:(id )key { - id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); - originalObject = [_dict objectForKey:key]; [_dict setObject:anObject forKeyedSubscript:key]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } - originalObject = nil; } - (NSArray *)allKeys @@ -195,32 +189,24 @@ - (NSArray *)allValues - (void)removeObjectForKey:(id)aKey { - id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); - originalObject = [_dict objectForKey:aKey]; - if (originalObject) { - [_dict removeObjectForKey:aKey]; - } + [_dict removeObjectForKey:aKey]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } - originalObject = nil; } - (void)removeAllObjects { - NSArray* allValues = nil; // make sure that objects are not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); - allValues = [_dict allValues]; [_dict removeAllObjects]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } - allValues = nil; } - (id)copy diff --git a/weex_core/Source/core/layout/flex_enum.h b/weex_core/Source/core/layout/flex_enum.h index 7e439b21ed..9eb3676354 100644 --- a/weex_core/Source/core/layout/flex_enum.h +++ b/weex_core/Source/core/layout/flex_enum.h @@ -16,14 +16,12 @@ * specific language governing permissions and limitations * under the License. */ +#ifdef __cplusplus #ifndef WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H #define WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H -/* These enum definitions may also be used by C files. */ -#ifdef __cplusplus namespace WeexCore { -#endif /** * MainAxis direction @@ -122,8 +120,6 @@ namespace WeexCore { kLeft, }; -#ifdef __cplusplus } -#endif - #endif //WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H +#endif \ No newline at end of file diff --git a/weex_core/Source/core/layout/layout.h b/weex_core/Source/core/layout/layout.h index 4b8f0c54df..0d62edd1df 100644 --- a/weex_core/Source/core/layout/layout.h +++ b/weex_core/Source/core/layout/layout.h @@ -836,7 +836,7 @@ namespace WeexCore { } } - inline WXCorePositionType getStylePositionType() const { + inline WXCorePositionType getStypePositionType() const { return mCssStyle->mPositionType; } diff --git a/weex_core/Source/core/render/page/render_page.cpp b/weex_core/Source/core/render/page/render_page.cpp index 119af879ec..032a0d7aa0 100644 --- a/weex_core/Source/core/render/page/render_page.cpp +++ b/weex_core/Source/core/render/page/render_page.cpp @@ -628,11 +628,13 @@ void RenderPage::Batch() { if ((kUseVSync && this->need_layout_.load()) || !kUseVSync) { LayoutInner(); } + else { #if OS_IOS - // vsync may stopped, trigger once - RenderAction *action = new RenderActionTriggerVSync(page_id()); - PostRenderAction(action); + // vsync may stopped, trigger once + RenderAction *action = new RenderActionTriggerVSync(page_id()); + PostRenderAction(action); #endif + } } RenderObject *RenderPage::GetRenderObject(const std::string &ref) { From c4847bb8a95747ea8fdc9f2e99d161a581e9106d Mon Sep 17 00:00:00 2001 From: Douma Fang Date: Fri, 9 Nov 2018 16:37:39 +0800 Subject: [PATCH 13/20] [iOS] fix scrollEnd can not get offset (#1729) --- ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm index dfe8824891..a27820222b 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm @@ -903,7 +903,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL } if (!decelerate) { _isScrolling = NO; - [self performSelector:@selector(scrollViewDidEndDecelerating:) withObject:nil afterDelay:0.1]; + [self performSelector:@selector(scrollViewDidEndDecelerating:) withObject:scrollView afterDelay:0.1]; } NSHashTable *delegates = [_delegates copy]; From ca545a5891fbd0baad5b8a6dfc993912b0d9b4a6 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Sat, 10 Nov 2018 22:54:57 +0800 Subject: [PATCH 14/20] [iOS] Remove specific animation by key instead of removing all. If we don' t remove, updating transform won't work after doing CAAnimation. http://dotwe.org/vue/ce7d8d3bd4e67d3fe321c9e8b0bbbb7b (#1734) --- ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m index 70a8feba25..75b09d8d01 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m +++ b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m @@ -123,7 +123,7 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag _animationInfo.target.view.layer.anchorPoint = _animationInfo.originAnchorPoint; _animationInfo.target.view.layer.frame = originFrame; } - [_animationInfo.target.layer removeAllAnimations]; + [_animationInfo.target.layer removeAnimationForKey:_animationInfo.propertyName]; if (_finishBlock) { _finishBlock(flag); From ac18368ec65bbfea77e0d7d669db9f8262d96b01 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Wed, 14 Nov 2018 15:49:08 +0800 Subject: [PATCH 15/20] [iOS] Fix deadlock if WXSDKInstance is release in thread safe dictionary. (#1757) --- ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m | 13 ++----------- .../Utility/WXThreadSafeMutableDictionary.m | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m index 87bc32650b..613abd59a4 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m @@ -78,7 +78,6 @@ @implementation WXSDKInstance BOOL _debugJS; id _instanceJavaScriptContext; // sandbox javaScript context CGFloat _defaultPixelScaleFactor; - BOOL _bReleaseInstanceInMainThread; BOOL _defaultDataRender; } @@ -118,7 +117,6 @@ - (instancetype)init _apmInstance = [[WXApmForInstance alloc] init]; _defaultPixelScaleFactor = CGFLOAT_MIN; - _bReleaseInstanceInMainThread = YES; _defaultDataRender = NO; [self addObservers]; @@ -443,9 +441,6 @@ - (BOOL)_handleConfigCenter BOOL useJSCApiForCreateInstance = [[configCenter configForKey:@"iOS_weex_ext_config.useJSCApiForCreateInstance" defaultValue:@(YES) isDefault:NULL] boolValue]; [WXUtility setUseJSCApiForCreateInstance:useJSCApiForCreateInstance]; - - //Reading config from orange for Release instance in Main Thread or not - _bReleaseInstanceInMainThread = [[configCenter configForKey:@"iOS_weex_ext_config.releaseInstanceInMainThread" defaultValue:@(YES) isDefault:nil] boolValue]; BOOL shoudMultiContext = NO; shoudMultiContext = [[configCenter configForKey:@"iOS_weex_ext_config.createInstanceUsingMutliContext" defaultValue:@(YES) isDefault:NULL] boolValue]; @@ -659,13 +654,9 @@ - (void)destroyInstance [WXCoreBridge closePage:instanceId]; // Reading config from orange for Release instance in Main Thread or not, for Bug #15172691 +{ - if (!_bReleaseInstanceInMainThread) { + dispatch_async(dispatch_get_main_queue(), ^{ [WXSDKManager removeInstanceforID:instanceId]; - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - [WXSDKManager removeInstanceforID:instanceId]; - }); - } + }); //+} }); diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m b/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m index 3c32292269..6f31fb990e 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m @@ -145,24 +145,30 @@ - (NSEnumerator *)keyEnumerator - (void)setObject:(id)anObject forKey:(id)aKey { + id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); + originalObject = [_dict objectForKey:aKey]; [_dict setObject:anObject forKey:aKey]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + originalObject = nil; } - (void)setObject:(id)anObject forKeyedSubscript:(id )key { + id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); + originalObject = [_dict objectForKey:key]; [_dict setObject:anObject forKeyedSubscript:key]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + originalObject = nil; } - (NSArray *)allKeys @@ -189,24 +195,32 @@ - (NSArray *)allValues - (void)removeObjectForKey:(id)aKey { + id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); - [_dict removeObjectForKey:aKey]; + originalObject = [_dict objectForKey:aKey]; + if (originalObject) { + [_dict removeObjectForKey:aKey]; + } } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + originalObject = nil; } - (void)removeAllObjects { + NSArray* allValues = nil; // make sure that objects are not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); + allValues = [_dict allValues]; [_dict removeAllObjects]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + allValues = nil; } - (id)copy From 6b9cbe0af5c8110ad7384fa512afa5dd03f6e857 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Wed, 14 Nov 2018 18:53:06 +0800 Subject: [PATCH 16/20] [iOS] Trigger vsync on iOS in every batch. (#1759) --- weex_core/Source/core/render/page/render_page.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/weex_core/Source/core/render/page/render_page.cpp b/weex_core/Source/core/render/page/render_page.cpp index 032a0d7aa0..119af879ec 100644 --- a/weex_core/Source/core/render/page/render_page.cpp +++ b/weex_core/Source/core/render/page/render_page.cpp @@ -628,13 +628,11 @@ void RenderPage::Batch() { if ((kUseVSync && this->need_layout_.load()) || !kUseVSync) { LayoutInner(); } - else { #if OS_IOS - // vsync may stopped, trigger once - RenderAction *action = new RenderActionTriggerVSync(page_id()); - PostRenderAction(action); + // vsync may stopped, trigger once + RenderAction *action = new RenderActionTriggerVSync(page_id()); + PostRenderAction(action); #endif - } } RenderObject *RenderPage::GetRenderObject(const std::string &ref) { From fd4b750326014aecf063b975f77bb7029a13a44d Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Mon, 19 Nov 2018 19:29:29 +0800 Subject: [PATCH 17/20] [iOS] Add completion callback for registerService (#1776) --- ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h | 30 ++++++++++++++++++- ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 17 +++++++++-- .../WeexSDK/Sources/Manager/WXBridgeManager.h | 7 +++-- .../WeexSDK/Sources/Manager/WXBridgeManager.m | 26 ++++++++++++---- 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h index 5e7b1e7db6..ac014a5781 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h @@ -82,6 +82,20 @@ */ + (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options; +/** + * @abstract Registers a component for a given name, options and js code + * + * @param name The service name to register + * + * @param options The service options to register + * + * @param serviceScript service js code to invoke + * + * @param completion Completion callback. JS is executed in asynchronously. + * + */ ++ (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; + /** * @abstract Registers a component for a given name, options and js url * @@ -92,7 +106,21 @@ * @param serviceScriptUrl The service url to register * */ -+ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl WithOptions:(NSDictionary *)options; ++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options; + +/** + * @abstract Registers a component for a given name, options and js url + * + * @param name The service name to register + * + * @param options The service options to register + * + * @param serviceScriptUrl The service url to register + * + * @param completion Completion callback. JS is executed in asynchronously. + * + */ ++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; /** * @abstract Registers a component for a given name, options and js code diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m index b5d7e00825..26ca8b7714 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m @@ -166,14 +166,25 @@ + (void)registerComponent:(NSString *)name withClass:(Class)clazz withProperties # pragma mark Service Register + + (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options { - [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options]; + [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options completion:nil]; +} + ++ (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion +{ + [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options completion:completion]; +} + ++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options +{ + [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options completion:nil]; } -+ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl WithOptions:(NSDictionary *)options ++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion { - [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options]; + [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options completion:completion]; } + (void)unregisterService:(NSString *)name diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h index 3d062774b7..8728161254 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h +++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h @@ -102,8 +102,9 @@ extern void WXPerformBlockOnBridgeThread(void (^block)(void)); * @param name : service name * @param serviceScript : script code * @param options : service options + * @param completion : completion callback **/ -- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options; +- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; /** @@ -111,9 +112,9 @@ extern void WXPerformBlockOnBridgeThread(void (^block)(void)); * @param name : service name * @param serviceScriptUrl : script url * @param options : service options + * @param completion : completion callback **/ - --(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options; +-(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion; /** * Unregister JS service Script diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m index a0e8e4e2a2..f5c7a47e7d 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m @@ -288,28 +288,41 @@ - (JSValue *)callJSMethodWithResult:(WXCallJSMethod *)method return value; } --(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options +- (void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion { - if (!name || !serviceScriptUrl || !options) return; + if (!name || !serviceScriptUrl || !options) { + if (completion) { + completion(NO); + } + return; + } __weak typeof(self) weakSelf = self; WXResourceRequest *request = [WXResourceRequest requestWithURL:serviceScriptUrl resourceType:WXResourceTypeServiceBundle referrer:@"" cachePolicy:NSURLRequestUseProtocolCachePolicy]; WXResourceLoader *serviceBundleLoader = [[WXResourceLoader alloc] initWithRequest:request];; serviceBundleLoader.onFinished = ^(WXResourceResponse *response, NSData *data) { __strong typeof(weakSelf) strongSelf = weakSelf; NSString *jsServiceString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - [strongSelf registerService:name withService:jsServiceString withOptions:options]; + [strongSelf registerService:name withService:jsServiceString withOptions:options completion:completion]; }; serviceBundleLoader.onFailed = ^(NSError *loadError) { WXLogError(@"No script URL found"); + if (completion) { + completion(NO); + } }; [serviceBundleLoader start]; } -- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options +- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion { - if (!name || !serviceScript || !options) return; + if (!name || !serviceScript || !options) { + if (completion) { + completion(NO); + } + return; + } NSString *script = [WXServiceFactory registerServiceScript:name withRawScript:serviceScript withOptions:options]; @@ -318,6 +331,9 @@ - (void)registerService:(NSString *)name withService:(NSString *)serviceScript w // save it when execute [WXDebugTool cacheJsService:name withScript:serviceScript withOptions:options]; [weakSelf.bridgeCtx executeJsService:script withName:name]; + if (completion) { + completion(YES); + } }); } From 8cf3513aea2a67f237d60e2e5aad96f94bfc3679 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Tue, 20 Nov 2018 13:31:31 +0800 Subject: [PATCH 18/20] [iOS] Forbid adjustment of safeArea by system for cycle slider component. (#1780) --- ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm index 402e592c7a..ab26bc3655 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm @@ -73,6 +73,9 @@ - (id)initWithFrame:(CGRect)frame _currentIndex = 0; _itemViews = [[NSMutableArray alloc] init]; _scrollView = [[WXRecycleSliderScrollView alloc] init]; + if (@available(iOS 11.0, *)) { + _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; + } _scrollView.backgroundColor = [UIColor clearColor]; _scrollView.delegate = self; _scrollView.showsHorizontalScrollIndicator = NO; From 942f0c561de5098a54c2b2ad54f28094a9133b12 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Wed, 21 Nov 2018 13:11:22 +0800 Subject: [PATCH 19/20] [iOS] Add methods to retrieve css style values from weexcore c++ object. --- .../Sources/Layout/WXComponent+Layout.h | 72 ++++++++++++++++- .../Sources/Layout/WXComponent+Layout.mm | 80 +++++++++++++++++++ weex_core/Source/core/layout/flex_enum.h | 8 +- weex_core/Source/core/layout/layout.h | 2 +- 4 files changed, 158 insertions(+), 4 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h index a33884769c..7a7dc37ff7 100644 --- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h +++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h @@ -26,6 +26,13 @@ #ifdef __cplusplus #include "layout.h" +typedef WeexCore::WXCoreFlexDirection WXCoreFlexDirection; +typedef WeexCore::WXCoreFlexWrap WXCoreFlexWrap; +typedef WeexCore::WXCoreJustifyContent WXCoreJustifyContent; +typedef WeexCore::WXCoreAlignItems WXCoreAlignItems; +typedef WeexCore::WXCoreAlignSelf WXCoreAlignSelf; +typedef WeexCore::WXCorePositionType WXCorePositionType; + extern "C" { #endif bool flexIsUndefined(float value); @@ -33,6 +40,19 @@ extern "C" { } #endif +#ifndef __cplusplus +// Ensure that .m files can use css style enum definitions. +#include "flex_enum.h" + +typedef enum WXCoreFlexDirection WXCoreFlexDirection; +typedef enum WXCoreFlexWrap WXCoreFlexWrap; +typedef enum WXCoreJustifyContent WXCoreJustifyContent; +typedef enum WXCoreAlignItems WXCoreAlignItems; +typedef enum WXCoreAlignSelf WXCoreAlignSelf; +typedef enum WXCorePositionType WXCorePositionType; + +#endif + @interface WXComponent () { @package @@ -51,9 +71,59 @@ extern "C" { * @warning Subclasses must not override this. */ #ifdef __cplusplus -@property(nonatomic, readonly, assign) WeexCore::WXCoreLayoutNode *flexCssNode; +@property (nonatomic, readonly, assign) WeexCore::WXCoreLayoutNode *flexCssNode; #endif +/** + * @abstract Get css style value for key. The key should be of CSS standard form. + * This method is for convenience use in C/ObjC environment. And if you want to + * retrieve all style values or in C++, you could use flexCssNode directly. + * + * Thread usage: + * This method should be invoked in component thread by WXPerformBlockOnComponentThread. + * Note that all initWithRef methods of WXComponent and its subclasses are performed in + * component thread by default. Therefore you can call this method directly in initWithRef. + * + * Supported keys: + * width, height, min-width, min-height, max-width, max-height, + * margin-(left/right/top/bottom) + * padding-(left/right/top/bottom) + * border-(left/right/top/bottom)-width + * left, right, top, bottom + * flex-grow + */ +- (float)getCssStyleValueForKey:(NSString *)key; + +/** + * @abstract Get css style flex-direction. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCoreFlexDirection)getCssStyleFlexDirection; + +/** + * @abstract Get css style flex-wrap. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCoreFlexWrap)getCssStyleFlexWrap; + +/** + * @abstract Get css style justify-content. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCoreJustifyContent)getCssStyleJustifyContent; + +/** + * @abstract Get css style align-items. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCoreAlignItems)getCssStyleAlignItems; + +/** + * @abstract Get css style align-self. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCoreAlignSelf)getCssStyleAlignSelf; + +/** + * @abstract Get css style position. Thread usage the same as getCssStyleValueForKey. + */ +- (WXCorePositionType)getCssStylePositionType; + /** * @abstract Convert layout dimension value like 'left', 'width' to style value in js considering viewport and scale. */ diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm index 18cb24dbb1..8afd225d18 100644 --- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm +++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm @@ -366,6 +366,86 @@ - (CGFloat)judgePropValuePropValue:(id)propValue defaultValue:(CGFloat)defaultVa return defaultValue; } +- (float)getCssStyleValueForKey:(NSString *)key +{ + /* + * width, height, min-width, min-height, max-width, max-height, + * margin-(left/right/top/bottom) + * padding-(left/right/top/bottom) + * border-(left/right/top/bottom)-width + * left, right, top, bottom + * flex-grow + */ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + if (_flexCssNode == nullptr) { + return NAN; + } + + std::string ckey = [key UTF8String]; + if (ckey == "width") return _flexCssNode->getStyleWidth(); + if (ckey == "height") return _flexCssNode->getStyleHeight(); + if (ckey == "min-width") return _flexCssNode->getMinWidth(); + if (ckey == "min-height") return _flexCssNode->getMinHeight(); + if (ckey == "max-width") return _flexCssNode->getMaxWidth(); + if (ckey == "max-height") return _flexCssNode->getMaxHeight(); + if (ckey == "margin-left") return _flexCssNode->getMarginLeft(); + if (ckey == "margin-right") return _flexCssNode->getMarginRight(); + if (ckey == "margin-top") return _flexCssNode->getMarginTop(); + if (ckey == "margin-bottom") return _flexCssNode->getMarginBottom(); + if (ckey == "padding-left") return _flexCssNode->getPaddingLeft(); + if (ckey == "padding-right") return _flexCssNode->getPaddingRight(); + if (ckey == "padding-top") return _flexCssNode->getPaddingTop(); + if (ckey == "padding-bottom") return _flexCssNode->getPaddingBottom(); + if (ckey == "border-left-width") return _flexCssNode->getBorderWidthLeft(); + if (ckey == "border-right-width") return _flexCssNode->getBorderWidthRight(); + if (ckey == "border-top-width") return _flexCssNode->getBorderWidthTop(); + if (ckey == "border-bottom-width") return _flexCssNode->getBorderWidthBottom(); + if (ckey == "left") return _flexCssNode->getStylePositionLeft(); + if (ckey == "right") return _flexCssNode->getStylePositionRight(); + if (ckey == "top") return _flexCssNode->getStylePositionTop(); + if (ckey == "bottom") return _flexCssNode->getStylePositionBottom(); + if (ckey == "flex-grow") return _flexCssNode->getFlex(); + + WXAssert(NO, @"Invalid css style key %@", key); + return NAN; +} + +- (WXCoreFlexDirection)getCssStyleFlexDirection +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getFlexDirection() : kFlexDirectionColumn; +} + +- (WXCoreFlexWrap)getCssStyleFlexWrap +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getFlexWrap() : kNoWrap; +} + +- (WXCoreJustifyContent)getCssStyleJustifyContent +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getJustifyContent() : kJustifyFlexStart; +} + +- (WXCoreAlignItems)getCssStyleAlignItems +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getAlignItems() : kAlignItemsStretch; +} + +- (WXCoreAlignSelf)getCssStyleAlignSelf +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getAlignSelf() : kAlignSelfAuto; +} + +- (WXCorePositionType)getCssStylePositionType +{ + WXAssert(_flexCssNode != nullptr, @"Css node is null."); + return _flexCssNode ? _flexCssNode->getStylePositionType() : kRelative; +} + - (NSString*)convertLayoutValueToStyleValue:(NSString*)valueName { if (_flexCssNode == nullptr) { diff --git a/weex_core/Source/core/layout/flex_enum.h b/weex_core/Source/core/layout/flex_enum.h index 9eb3676354..7e439b21ed 100644 --- a/weex_core/Source/core/layout/flex_enum.h +++ b/weex_core/Source/core/layout/flex_enum.h @@ -16,12 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -#ifdef __cplusplus #ifndef WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H #define WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H +/* These enum definitions may also be used by C files. */ +#ifdef __cplusplus namespace WeexCore { +#endif /** * MainAxis direction @@ -120,6 +122,8 @@ namespace WeexCore { kLeft, }; +#ifdef __cplusplus } +#endif + #endif //WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H -#endif \ No newline at end of file diff --git a/weex_core/Source/core/layout/layout.h b/weex_core/Source/core/layout/layout.h index 0d62edd1df..4b8f0c54df 100644 --- a/weex_core/Source/core/layout/layout.h +++ b/weex_core/Source/core/layout/layout.h @@ -836,7 +836,7 @@ namespace WeexCore { } } - inline WXCorePositionType getStypePositionType() const { + inline WXCorePositionType getStylePositionType() const { return mCssStyle->mPositionType; } From 5702b656a1dae32fdfe6a82749a92e9bf58cea3c Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Wed, 21 Nov 2018 16:06:03 +0800 Subject: [PATCH 20/20] [Android] Fix mistype. --- .../wrap/native_render_object_utils_impl_android.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/weex_core/Source/android/wrap/native_render_object_utils_impl_android.cpp b/weex_core/Source/android/wrap/native_render_object_utils_impl_android.cpp index 5565075a01..eb30d90d72 100644 --- a/weex_core/Source/android/wrap/native_render_object_utils_impl_android.cpp +++ b/weex_core/Source/android/wrap/native_render_object_utils_impl_android.cpp @@ -79,7 +79,7 @@ static jlong CopyRenderObject(JNIEnv* env, jclass jcaller, jlong ptr){ static void showRenderObjectLayout(RenderObject *renderObject, int level){ LOGE("RenderObject layout %s %d %p %f %f %f %f ", renderObject->type().c_str(), - renderObject->getStypePositionType(), + renderObject->getStylePositionType(), renderObject, renderObject->getLayoutHeight(), renderObject->getLayoutWidth(), renderObject->getLayoutPositionLeft(), renderObject->getLayoutPositionRight()); @@ -171,11 +171,11 @@ static void RenderObjectChildWaste(JNIEnv* env, jclass jcaller, jboolean waster){ RenderObject* renderObject = convert_long_to_render_object(ptr); if(waster){ - if(renderObject->getStypePositionType() != WXCorePositionType::kFixed){ + if(renderObject->getStylePositionType() != WXCorePositionType::kFixed){ renderObject->setStylePositionType(WXCorePositionType::kFixed); } }else{ - if(renderObject->getStypePositionType() != WXCorePositionType::kRelative){ + if(renderObject->getStylePositionType() != WXCorePositionType::kRelative){ renderObject->setStylePositionType(WXCorePositionType::kRelative); } }