Layout Animation not working on Android (create() method) - android

I'm using LayoutAnimation for animating my <View>. I toggle it with:
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
this.showView = !this.showView;
but the animation is not working at the moment of create, only when the View disappears.
(iOS works perfect)

You need to add this code segment for Android.
import { UIManager, LayoutAnimation } from 'react-native';
...
if (Platform.OS === "android") {
UIManager.setLayoutAnimationEnabledExperimental &&
UIManager.setLayoutAnimationEnabledExperimental(true);
}

It was probably something wrong with the loading of text that was displayed in my View. Now I'm loading the text from the JSON file and it works.

Related

react native android keyboard empty space

I am trying to fix a problem we are having with the keyboard on android. Due to react-native-gifted-chat, we have to use android:windowSoftInputMode="adjustResize" instead of adjustPan. The problem is, that the chat breaks without adjustResize and all the other stuff (e.g. some textfields in a form) break without adjustPan. I also tried adjustResize|adjustPan, adjustPan|adjustResize and tried to use KeyboardAvoidingView on the Form components, but nothing seems to work. Here is how it looks like when using adjustResize without any KeyboardAvoidingView. It creates some not-clickable grey area above the keyboard. Note that there is no way around adjustResize due to the chat...
Thanks in advance!
For anyone struggling with the same:
The package react-native-set-soft-input-mode allows you to change the softInputMode, e.g. for the chat, the following works fine:
useEffect(() => {
if (Platform.OS === 'android') {
SoftInputMode.set(SoftInputMode.ADJUST_RESIZE);
}
return () => {
if (Platform.OS === 'android') {
SoftInputMode.set(SoftInputMode.ADJUST_PAN);
}
};
}, []);

When removing a View from render, it's background continues there on Android

I'm having a serious problem with React Native on Android.
Let's say I have the following render method:
render() {
let stuff = this.state.showStuff ? <Text style={styles.stuff}>Stuff</Text> : null
return (
<View>
{ stuff }
</View>
)
}
Really simple. If I want to hide the "Stuff", I just call:
this.setState({ showStuff: false })
This works fine on iOS, but on Android, if styles.stuff define a backgroundColor, the component will be re-rendered without the "stuff" content, but with it's background!
Now I have no idea on how to remove elements from my component, since this weird behavior broke how I used to think react native works.
I found out that react-native-searchbar was causing the issue on non-related views. Removing that component solved this and other non-related issues on my project.

Ionic 2 - how to prevent page changes on ion-slides by swipe gesture?

I saw the solution in many different sources for this, including Stack Overflow. This is working for me partially: I can't swipe to the left or right to switch the pages. That's fine ! But if the user click a button , keep the button pressed and swipe, this will cause pagination. (I just testing using Android)
The solution according with many sources is that one:
<ion-slides [options]="{onlyExternal: false}">
</ion-slides>
Let me illustrate this with screenshots...
If I swipe here, nothing will happen
Now, if I hold and swipe the red button, this will cause pagination.
The way i do this is:
On my .ts file of the page i have a slide i do this
import { Component, ViewChild } from '#angular/core';
import { Slides } from 'ionic-angular';
#Component({
selector: 'page',
templateUrl: 'page.html'
})
export class Page{
#ViewChild(Slides) slides: Slides;
contructor() {
this.slides.lockSwipes(true);
}
nextSlide(){
this.slides.lockSwipes(false);
this.slides.slideNext();
this.slides.lockSwipes(true);
}
}
And in your HTML you call the function on a button
<button ion-button block (tap)="nextSlide()">NEXT</button>
So when the page is beeing constructed i lock the swipe, and when someone click next/back i unlock the swipe, go to next slide and lock it back.
Hope it helps
Since externalOnly isn't working in Ionic 4 anymore, i looked into the Swiper API documentation and saw that it changed to allowTouchMove now.
So: <ion-slides [options]="{allowTouchMove:false}"
Another way to achieve it is adding the swiper-no-swiping class:
Example:
<ion-slides #slides class="swiper-no-swiping">
...
</ion-slides>
you should use the function ionViewDidLoad() because when you put the "this.slides.lockSwipes(true);" in the constructor, the page havent load yet, try to do this.
ionViewDidLoad(){
this.slides.lockSwipes(true);
}
Use the onlyExternal option. You can access it by ViewChild.
#ViewChild('slider') slider: Slides;
ionViewDidLoad() {
this.slider.onlyExternal = true;
this.slider.paginationClickable = false;
}
nextSlide() {
this.slider.slideNext();
}
<ion-slides pager #slider>
...
</ion-slides>
You can call nextSlide() e.g. by button within slide.
Update: paginationClickable does not work. :/
Currently this is the best solution to really control the behavior.
ionViewDidLoad() {
this.slider.lockSwipes(true);
}
nextSlide() {
this.slider.lockSwipes(false);
this.slider.slideNext();
this.slider.lockSwipes(true);
}

Titanium Flip animation for Android

I have superview (flashcardView ), i added the two subviews(frontView and backView) to this view. If user tap the any one of the view it flip and shows the other view. I am using the following code for achieve this functionality.
frontView.addEventListener('click', function(e) {
var animation = require('alloy/animation');
animation.flip( frontView,backView, 'horizontal',500, function(){
});
});
backView.addEventListener('click', function(e) {
var animation = require('alloy/animation');
animation.flip( backView,frontView, 'horizontal',500, function(){
});
This code is only working in iOS devices. It is not working in Android devices. Pls suggest me to do the flip animation for Android.
In Titanium available animations depend on the system (iOS or Android) you use. Therefore the code you use is only working for iOS. As far as I know there is no built-in flip animation for Android. But there is a solution by another user he gave in this answer.
Here is the code he uses:
var anim_minimize = Titanium.UI.createAnimation({width:0,duration:500});
var anim_maximize = Titanium.UI.createAnimation({width:320,duration:500});
tabGroup.animate(anim_minimize);
setTimeout(function(){
tabGroup.animate(anim_maximize);
},500);
Basically he creates the views next to each other and uses another animation which should look the same as a flip animation.
Another option you could try is using a module such as Flipium.

Popup menu scroll with the page in jquerymobile

I have create an popup menu in my app the problem with it is when i open the popup menu and then scroll the page the popup menu also scrolls up with the page even i tried using data-dismissible="false" but nothing happen still the problem remains same.
Thanks in advance.
There's an easy fix for this problem. Just prevent page scrolling when popup is active.
Working jsFiddle example: http://jsfiddle.net/Gajotres/aJChc/
For this to work popup needs to have an attribute: data-dismissible="false" it will prevent popup closure when clicked outside of it. Another attribute can be used: data-overlay-theme="a" it will color popup overlay div. That is a DIV that covers screen when popup is opened and prevents popup closure.
And this javascript will work on every possible popup:
$(document).on('popupafteropen', '[data-role="popup"]' ,function( event, ui ) {
$('body').css('overflow','hidden');
}).on('popupafterclose', '[data-role="popup"]' ,function( event, ui ) {
$('body').css('overflow','auto');
});
For me this method didn't work, it works on browser but not in Phone Gap application.
So I resolve it in this way:
$('#Popup-id').on({
popupbeforeposition: function(){
$('body').on('touchmove', false);
},
popupafterclose: function(){
$('body').off('touchmove');
}
});
Hope it helps!
if body scrolling is not prevented, try below. in my case i was using boilerplate.css so the preventing the body scrolling not worked.
popupafteropen: function (e) {
$('html').css('overflow', 'hidden');
},
popupafterclose: function (e) {
$('html').css('overflow', 'auto');
}

Categories

Resources