Hi,
I want to make a comment input area in my App which has functionality which is similar to that found on Facebook. A short description of the functionality is a comment input area which starts of as one line and which extends to more lines as you write. As you keep on writhing to you get to a fixed height and the input area then changes to a scroll view.
I have been looking at a combination of TextView and ScrollView to achieve this functionality, but I don’t manage to give the focus back to the ScrollView if the user is typing to allow for scrolling.
Any suggestions on how to create this functionality?
Here is my current implementation which does not work:
<App>
<JavaScript>
var Observable = require("FuseJS/Observable");
var showScrollIndicator = Observable(false);
var commentHeight = Observable(false);
function textInputHeight (arg) {
if (arg.height > 130) {
commentHeight.value = true;
} else {
commentHeight.value = false;
}
}
function valueChanged () {
commentScrollView.gotoRelative(0, 1);
showScrollIndicator.value = false;
}
function scrollIndicatorActive () {
if (commentHeight.value == true) {
showScrollIndicator.value = true;
} else {
showScrollIndicator.value = false;
}
}
module.exports = {
valueChanged: valueChanged,
scrollIndicatorActive: scrollIndicatorActive,
showScrollIndicator: showScrollIndicator,
textInputHeight: textInputHeight,
commentHeight: commentHeight
};
</JavaScript>
<DockPanel ux:Name="makeComment" MaxHeight="150">
<Panel Dock="Left" Alignment="Bottom">
<Image Margin="10,5,10,5" Width="30" Height="30" File="../assets/images/user-avatar-blue.png" Dock="Left" />
</Panel>
<Panel Dock="Left" Width="65%" MaxHeight="150" Padding="0,10,0,10" Alignment="Left">
<WhileTrue Value="{showScrollIndicator}" >
<Rectangle Height="50%" Width="2" Margin="2,0,2,0" Alignment="TopRight" ux:Name="scrollIndicator" Opacity="0">
<SolidColor Color="#ddd" />
</Rectangle>
<GiveFocus Target="commentScrollView" />
<BringToFront Target="commentScrollView" />
</WhileTrue>
<ScrollView ux:Name="commentScrollView" SnapMinTransform="true" SnapMaxTransform="true" KeepFocusInView="false" LayoutMode="PreserveScrollPosition" Focus.IsFocusable="true">
<WhileInteracting>
<Change scrollIndicator.Opacity="1" />
<GiveFocus Target="commentScrollView" />
<BringToFront Target="commentScrollView" />
</WhileInteracting>
<ScrollingAnimation>
<Move Y="0.5" RelativeNode="commentScrollView" RelativeTo="Size" Target="scrollIndicator" />
</ScrollingAnimation>
<DockPanel HitTestMode="LocalVisualAndChildren">
<TextView Value="{Comment}" ux:Name="postCommen" ValueChanged="{valueChanged}" TextWrapping="Wrap" FontSize="16" Moved="{scrollIndicatorActive}" Placed="{textInputHeight}" >
<WhileString Test="IsEmpty">
<Text TextWrapping="Wrap" TextColor="#878c93" FontSize="16" Alignment="Left" >Write a comment</Text>
<Set Post.TextColor="#878c93" />
<Set scrollIndicator.Opacity="0" />
</WhileString>
<WhileString Test="IsNotEmpty">
<Set Post.TextColor="red" />
</WhileString>
<WhileFocusWithin>
<Change scrollIndicator.Opacity="0" />
</WhileFocusWithin>
</TextView>
</DockPanel>
</ScrollView>
</Panel>
<Panel Dock="Right" Alignment="Bottom">
<Text ux:Name="Post" Margin="10,10,10,0" Value="Post" Height="30" FontSize="16" TextColor="#878c93" />
</Panel>
</DockPanel>
</App>